Android的TextView的带有滚动条和了maxHeight [英] Android TextView with scrollbars and maxHeight

查看:629
本文介绍了Android的TextView的带有滚动条和了maxHeight的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要设置TextView的最大高度(使用或了maxHeight MAXLINES)。如果有更多的行文字应显示的滚动条。我应该使用这个标记是什么?

I need to set the TextView maximum height (either using maxHeight or maxLines). And if there are more lines of text the scrollbars should be shown. What markup should I use for this?

最初的想法是包裹的TextView与滚动型,但滚动型无属性了maxHeight

Initial idea was to wrap TextView with ScrollView, but ScrollView has no maxHeight attribute.

推荐答案

布局:

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

code:

Code:

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

请注意:

Android的:文字颜色=@机器人:彩色/ secondary_text_dark_nodisable是为了避免文字淡出TextView的时候被触摸

The android:textColor="@android:color/secondary_text_dark_nodisable" is used to avoid text fade out when textView is touched.

这篇关于Android的TextView的带有滚动条和了maxHeight的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆