html5中文学习网

您的位置: 首页 > android » 正文

android TextView不用ScrollViewe也可以滚动的方法_Android_脚本之家

[ ] 已经帮助:人解决问题

代码

复制代码 代码如下:

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>
 

(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助