竹山一叶

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
利用ScrollView 来控制textView 显示的行数
<ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbars="vertical" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
            <span style="white-space:pre">	</span>android:maxLines="4"	//设置最大显示行数 4行
                android:scrollbars="vertical"//设置 滚动方向
                android:singleLine="false"//设置不为单行
                android:textColor="@color/white"
                android:textSize="16sp" />
        </LinearLayout>
    </ScrollView>

这个控件的目的是 最大显示四行,超过四行的有滚动条,滚动显示所有内容

还有一步,在 初始化 该textView的时候,

title = (TextView) findViewById(R.id.title);
title.setMovementMethod(ScrollingMovementMethod.getInstance());
这样就大功告成了!!



posted on 2017-06-19 13:13  竹山一叶  阅读(936)  评论(0编辑  收藏  举报