一、Xml代碼
- <TextView
- android:id="@+id/textview"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:singleLine="false"
- android:maxLines="5"
- android:scrollbars="vertical"
- />
二、還需要在代碼中設置 TextView 相應的方法
- TextView textView = (TextView)findViewById(R.id.text_view);
- textView.setMovementMethod(ScrollingMovementMethod.getInstance());
好了,大功告成。
附:
順便講下 TextView 自動滾動的實現方法,下面介紹兩種方法:
一、在代碼中實現:
textView .setEllipsize(TextUtils.TruncateAt.MARQUEE);
textView .setSingleLine(true);
textView .setMarqueeRepeatLimit(6);
二、在XML中實現:
<TextView android:id="@+id/TextView01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:singleLine="true"
android:text="dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"
android:marqueeRepeatLimit="marquee_forever" android:ellipsize="marquee"
android:scrollHorizontally="true" android:width="150dip"></TextView>
一切OK,當 textView 獲取焦點後,就會自動滾動。