分享

Android 设置TextView滑动滚动条和滑动效果

 黄三岁大爱人生 2019-10-03

1、单独的TextView控件设置滚动条

        <TextView
                android:id='@+id/content'
                android:layout_width='fill_parent'
                android:layout_height='wrap_content'
                android:text='file content is empty!'
                android:scrollbars='vertical'
                android:fadeScrollbars='false'
/>

在activity中为这个TextView设置:

  mFileContentView = (TextView) findViewById(R.id.content);
  mFileContentView.setMovementMethod(ScrollingMovementMethod.getInstance());

经过上面两个步骤,TextView就可以上下滚动了,如果想自定义滚动条,接着在xml里面加入属性:

android:scrollbarThumbVertical='@drawable/ic_launcher'   //滑块的图片
android:scrollbarTrackVertical='@drawable/ic_launcher'   //滑道的图片

ScrollBar由两部分组成,一个是Track(滑道),一个是Thumb(滑块)

2、也可以用ScrollView

    <ScrollView
            android:layout_width='fill_parent'
            android:layout_height='wrap_content'
            android:scrollbars='vertical'
            android:fadingEdge='vertical'>

        <TextView
                android:id='@+id/content'
                android:layout_width='fill_parent'
                android:layout_height='wrap_content'
                android:text='file content is empty!'/>
    </ScrollView>



    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约