MarqueeTextView.java //新建一个自定义控件,继承TextView就行
public class MarqueeTextView extends android.support.v7.widget.AppCompatTextView{
public MarqueeTextView(Context context) {
super(context);
}
public MarqueeTextView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public MarqueeTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public boolean isFocused() {
return true;
}
}
bfrag.xml //在你要显示的xml调用
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f0f"
android:gravity="center"
android:orientation="vertical">
<fanruiqi.bwie.com.week220181205.util.MarqueeTextView
android:id="@+id/tv_runHorseLamp1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:singleLine="true"
android:text="这是一段很长的威武霸气的滚动的实现跑马灯效果的一段逼格很高的很有含义和涵养的文字"
/>
<ImageView
android:id="@+id/b_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
/>
<Button
android:id="@+id/b_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="退出登录"/>
</LinearLayout>