android TextView添加滾動條有兩種方法
方法一:
Android預設TextView如果在一螢幕顯示不下的話,是不會有滾動條的,解決方法是在<TextView>外面添加<ScrollView>标簽;
1.<ScrollView
2. android:layout_width="fill_parent"
3. android:layout_height="wrap_content" >
4.
5. <TextView
6. android:layout_width="fill_parent"
7. android:layout_height="wrap_content"
8. android:textSize="50dp"
9. android:text="1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\12a\n13\n14\n" />
10.</ScrollView>
方法二:
經驗證, 以下方法可用:
一、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.setScrollbarFadingEnabled(false);