Android-TextView

来源:互联网 发布:ovs linux网桥 编辑:程序博客网 时间:2024/05/22 04:42

一。实现一行长字幕滚动效果

   <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:singleLine="true"        android:ellipsize="marquee"        android:focusable="true"        android:focusableInTouchMode="true"        android:text="@string/hello_world" /></RelativeLayout>

二。实现一行长字幕滚动效果

先新建marqueetext类

public class MarqueeText extends TextView {    public MarqueeText(Context context) {        super(context);    }    public MarqueeText(Context context, AttributeSet attrs, int defStyle){        super(context,attrs,defStyle);    }    public MarqueeText(Context context, AttributeSet attrs){        super(context,attrs);    }    public boolean isFocused(){        return true;    }}
activity_main改成
    <com.example.fang.text3.MarqueeText        android:id="@+id/textview1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:singleLine="true"        android:ellipsize="marquee"        android:focusable="true"        android:focusableInTouchMode="true"        android:text="@string/hello_world" />    <com.example.fang.text3.MarqueeText        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginTop="20dp"        android:singleLine="true"        android:ellipsize="marquee"        android:focusable="true"        android:focusableInTouchMode="true"        android:text="@string/hello_world" /></RelativeLayout>



0 0
原创粉丝点击