当前位置: 移动技术网 > 移动技术>移动开发>Android > android TextView不用ScrollViewe也可以滚动的方法

android TextView不用ScrollViewe也可以滚动的方法

2019年07月24日  | 移动技术网移动技术  | 我要评论

代码

复制代码 代码如下:

textview textview = (textview) findviewbyid(r.id.text);
            /**             *
             * 只有调用了该方法,textview才能不依赖于scrollview而实现滚动的效果。
             * 要在xml中设置textview的textcolor,否则,当textview被触摸时,会灰掉。
             */

            textview.setmovementmethod(scrollingmovementmethod.getinstance());
 

xml文件

复制代码 代码如下:

<textview
   xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:textsize="18sp"
  android:scrollbars="vertical"
   android:maxlines="12"
  android:textcolor="@color/white"
  android:text="@string/str"
  android:id="@+id/text"
  ></textview>
 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网