我需要设置TextView最大高度(使用maxHeight或maxLines).如果有更多行文本,则应显示滚动条.我应该使用什么标记呢?
最初的想法是使用ScrollView包装TextView,但ScrollView没有maxHeight属性.
ale*_*2k8 61
布局:
<TextView
android:id="@+id/text_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="false"
android:maxLines="3"
android:scrollbars="vertical"
android:textColor="@android:color/secondary_text_dark_nodisable"
>
</TextView>
Run Code Online (Sandbox Code Playgroud)
码:
TextView textView = (TextView)findViewById(R.id.text_view);
textView.setMovementMethod(ScrollingMovementMethod.getInstance());
Run Code Online (Sandbox Code Playgroud)
注意:
android:textColor ="@ android:color/secondary_text_dark_nodisable"用于避免触摸textView时文本淡出.
| 归档时间: |
|
| 查看次数: |
22492 次 |
| 最近记录: |