<TextView android:id="@+id/authorMessage" android:layout_width="match_parent" android:layout_height="70dp" android:layout_marginLeft="16dp" android:layout_marginTop="12dp" android:layout_marginRight="16dp" android:ellipsize="end" android:maxLines="3" android:lineSpacingMultiplier="1.2" android:text="XXXXXXXXXXXXXXXXXXXXXXXX" android:textColor="#645441" android:textSize="14dp" /> <TextView android:id="@+id/authorMessageMore" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:layout_marginBottom="0dp" android:layout_gravity="bottom" android:paddingTop="10dp" android:paddingBottom="10dp" android:ellipsize="end" android:maxLines="1" android:text="點擊查看全部" android:textColor="#C44F20" android:textSize="20dp" />
TextView mAuthorMessage = findViewById(R.id.authorMessage); TextView mAuthorMessageMore = findViewById(R.id.authorMessageMore); Layout l = mAuthorMessage.getLayout(); if (l != null) { int lines = l.getLineCount(); if (lines > 0) { if (l.getEllipsisCount(lines - 1) > 0) { sShowMore = true; mAuthorMessageMore.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { //顯示TextView的全部內容其實就是取消這類隱藏文字的屬性 mAuthorMessage.setEllipsize(null); mAuthorMessage.setSingleLine(false); mAuthorMessageMore.setVisibility(View.GONE); } }); } } }