日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android TextView 带滚动条,和ScrollView 用法(暂时觉得ScrollView滑动速度比较快)

發布時間:2025/6/15 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android TextView 带滚动条,和ScrollView 用法(暂时觉得ScrollView滑动速度比较快) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本來是想做一個顯示文字信息的,當文字很多時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"??
  • ????/>??
  • <TextViewandroid: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滑动速度比较快)的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。