用textview实现跑马灯效果

来源:互联网 发布:淘宝商品导入京东 编辑:程序博客网 时间:2024/06/05 04:18

1.在xml中设置textview

     <TextView
        android:id="@+id/index_maquree_txt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="12sp"
        android:textColor="@color/black"
        android:layout_centerInParent="true"
        android:paddingLeft="8dp"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:text="@string/index_news1"/>

2.在activity中添加获得焦点,同样focusableInTouchMode是滑动时能否获得焦点。

        TextView indexWeather = (TextView)view.findViewById(R.id.index_maquree_txt);

        //如果reportContent内容太多了的话,我们需要让其滚动起来,
        //具体可以查看SDK中android.text.method了解更多,代码如下:

        indexWeather.setMovementMethod(ScrollingMovementMethod.getInstance()) ;

0 0
原创粉丝点击