XML 設置 android:maxLines="4" 硬性限制顯示行數,超出部分被截斷或隱藏。
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
android:ellipsize="none" />
內容多少自適應高度。
TextView tv = findViewById(R.id.text);
tv.measure(0, 0); // 或在 layout 後
int height = tv.getLineCount() * tv.getLineHeight();
tv.setHeight(height);
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:scrollbars="vertical"
android:overScrollMode="always" />
textView.setMovementMethod(new ScrollingMovementMethod());
ValueAnimator。