Android Studio [跑马灯]
MainActivity
package com.xdw.secondapp;
import android.graphics.Paint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class TextViewActivity extends AppCompatActivity {
private TextView mtv5;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text_view);
mtv5=findViewById(R.id.tv_5);
mtv5.setSelected(true);
}
}
activity_text_view.xm
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:orientation="vertical"> <TextView android:id="@+id/tv_5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="瑞哥在奔跑瑞哥在奔跑瑞哥在奔跑瑞哥在奔跑" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:singleLine="true" android:focusable="true" android:scrollHorizontally="true" android:focusableInTouchMode="true" android:textColor="#000000" android:textSize="24sp" /> </LinearLayout>
//设置为跑马灯显示
android:ellipsize="marquee"
//获取焦点
android:focusable="true"
//可以通过toucth来获得focus
android:focusableInTouchMode="true"
//设置重复的次数
android:marqueeRepeatLimit="marquee_forever"
//单行显示文字
android:singleLine="true"