TextView实现跑马灯效果
xml文件中声明属性,使TextView获取焦点 核心属性:singleLine,ellipsize,focusable,focusableInTouchMode
<TextView
android:id="@+id/text_marquee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:text="跑马灯文字跑马灯文字跑马灯文字跑马灯文字跑马灯文字跑马灯文字"/>
2.acticity中加入如下代码
@Override
protected void onCreate(Bundle savedInstanceState
) {
super.onCreate(savedInstanceState
);
setContentView(R
.layout
.activity_text
);
TextView tv
= findViewById(R
.id
.text_marquee
);
tv
.setSelected(true);
}