带滚动条和maxHeight的Android文本视图

带滚动条和maxHeight的Android文本视图,android,Android,我需要设置TextView最大高度(使用maxHeight或maxLines)。如果有更多的文本行,则应显示滚动条。我应该为此使用什么标记 最初的想法是用ScrollView包装TextView,但ScrollView没有maxHeight属性。布局: <TextView android:id="@+id/text_view" android:layout_width="fill_parent" android:layout_height="wrap_content

我需要设置TextView最大高度(使用maxHeight或maxLines)。如果有更多的文本行,则应显示滚动条。我应该为此使用什么标记

最初的想法是用ScrollView包装TextView,但ScrollView没有maxHeight属性。

布局:

<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>
注:


android:textColor=“@android:color/secondary\u text\u dark\u nodisable”用于避免触摸textView时文本淡出。

当我尝试此操作时,textView显示滚动条,但实际上无法使其滚动。您必须从代码执行此操作:
TexView.setMovementMethod(new ScrollingMovementMethod())
;我使用这种方法是因为我不能省略超过两行。谢谢。@4年后你的回答帮助了我。浪费了一个小时来搞清楚这件事。
TextView textView = (TextView)findViewById(R.id.text_view);
textView.setMovementMethod(ScrollingMovementMethod.getInstance());