android TextView 带滚动条,和ScrollView 用法(暂时觉得ScrollView滑动速度比较快)
本來是想做一個顯示文字信息的,當文字很多時View的高度不能超過一個固定的值,當文字很少時View的高度小于那個固定值時,按View的高度顯示。因為ScrollView沒有maxHeight,無法滿足需求,只好另找方法了。
?
View本身是可以設置ScrollBar,這樣就不一定需要依賴ScrollView了。TextView有個屬性maxLine,這樣也就滿足了需求了,只要設置一個TextView帶ScrollBar的,然后設置maxLine就可以了。
?
?
還需要在代碼了設置TextView可以滾動。
------------------------------------------------------------------------------------------------------------------------------------------
?
如果用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滑动速度比较快)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在android上面让TextView
- 下一篇: TextView 的ScrollView