代码之家  ›  专栏  ›  技术社区  ›  alex2k8

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

  •  21
  • alex2k8  · 技术社区  · 16 年前

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

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

    1 回复  |  直到 16 年前
        1
  •  65
  •   Cristian    15 年前

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

    代码:

    TextView textView = (TextView)findViewById(R.id.text_view);
    textView.setMovementMethod(ScrollingMovementMethod.getInstance());
    

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