Android文字跑马灯
16lz
2021-01-26
1. 继承TextView自定义控件
package com.anjoyo.musicplayer.define; import android.content.Context; import android.graphics.Rect; import android.util.AttributeSet; import android.widget.TextView; public class MarqueeTextView extends TextView { public MarqueeTextView(Context context) { super(context); // android:ellipsize="marquee" // android:focusable="true" // android:marqueeRepeatLimit="marquee_forever" // android:focusableInTouchMode="true" // android:scrollHorizontally="true" //// android:singleLine="true" // setSingleLine(true); // setEllipsize(TruncateAt.MARQUEE); // setFocusable(true); // setMarqueeRepeatLimit(Integer.MAX_VALUE); // setFocusableInTouchMode(true); } public MarqueeTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // TODO Auto-generated constructor stub } public MarqueeTextView(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } @Override protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { if (focused) { super.onFocusChanged(focused, direction, previouslyFocusedRect); } } @Override public void onWindowFocusChanged(boolean hasWindowFocus) { if (hasWindowFocus) { super.onWindowFocusChanged(hasWindowFocus); } } @Override public boolean isFocused() { return true; } }
2. 在布局中的使用
3. style.xml
更多相关文章
- android-仿iOS弹出框
- android中的有道词典
- Android(安卓)RecyclerView网格布局
- 自定义Dialog2
- Android(安卓)BaseFragment基类
- Android(安卓)Service系列(十)直接继承Service
- ANDROID -- Bluetooth
- Kotlin简单开发-RecyclerView
- Android(安卓)录制音频示例