標籤:
本來是想做一個顯示文字資訊的,當文字很多時View的高度不能超過一個固定的值,當文字很少時View的高度小於那個固定值時,按View的高度顯示。因為ScrollView沒有maxHeight,無法滿足需求,只好另找方法了。
View本身是可以設定ScrollBar,這樣就不一定需要依賴ScrollView了。TextView有個屬性maxLine,這樣也就滿足了需求了,只要設定一個TextView帶ScrollBar的,然後設定maxLine就可以了。
<TextView android:id="@+id/text_view" android:layout_width="fill_parent" android:layout_height="wrap_content" android:singleLine="false" android:maxLines="10" android:scrollbars="vertical" />
還需要在代碼了設定TextView可以滾動。
TextView textView = (TextView)findViewById(R.id.text_view); textView.setMovementMethod(ScrollingMovementMethod.getInstance());
如果用ScrollView ,代碼如下
<ScrollView android:layout_width="745dip" android:layout_height="520dip" android:id="@+id/mBtnRe2" android:layout_marginTop="30dip" android:layout_marginLeft="30dip" android:fadingEdge="none" > <TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/mTxtContent" android:textSize="25sp" android:textColor="#000000" android:fadingEdge="none" /></ScrollView>
ScrollView可以調整滑動速度,自己實現ScrollView
* 快/慢滑動ScrollView * @author 農民伯伯 * */ public class SlowScrollView extends ScrollView { public SlowScrollView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public SlowScrollView(Context context, AttributeSet attrs) { super(context, attrs); } public SlowScrollView(Context context) { super(context); } /** * 滑動事件 */ @Override public void fling(int velocityY) { super.fling(velocityY / 4); } }
android TextView 帶捲軸,和ScrollView 用法(暫時覺得ScrollView滑動速度比較快)