Android重写TextView实现文字跑马灯效果
2013-11-28 15:18
876 查看
/** * 重写TextView实现文字跑马灯效果 */ import android.content.Context; import android.graphics.Rect; import android.util.AttributeSet; import android.widget.TextView; /**@Discription: * @author Rose */ public class MarqueeTextView extends TextView{ private boolean scroll=false; /** * @param context * @param attrs */ 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 scroll; } /** * @return the scroll */ public boolean isScroll() { return scroll; } /** * @param scroll the scroll to set */ public void setScroll(boolean scroll) { this.scroll = scroll; } }
第一步:
1.实现以上的MarqueeTextView.
2.通过setScroll(true)来开启跑马灯。
第二步 :
1.xml中Text修改为
<com.包名.MarqueeTextView android:id="@+id/episode" android:layout_width="60dp" android:layout_height="wrap_content" android:ellipsize="marquee" android:gravity="center" android:marqueeRepeatLimit="marquee_forever" android:singleLine="true" android:text="第1集" android:textColor="@color/white" android:textSize="16sp" />其中重要属性有:
<1> android:ellipsize="marquee"
<2>android:marqueeRepeatLimit="marquee_forever"
<3>android:singleLine="true"
相关文章推荐
- android使用TextView实现文字的跑马灯效果
- Android中TextView实现文字跑马灯效果(滚动轮播)
- Android中使用TextView实现文字跑马灯效果
- 一分钟实现 Android textview 跑马灯文字滚动效果
- Android中继承TextView实现文字的跑马灯效果
- Android:TextView文字跑马灯的效果实现
- Android实现多个TextView同时显示跑马灯效果
- Android TextView 跑马灯效果的实现
- Android TextView实现跑马灯效果。
- Android TextView实现垂直滚动的跑马灯效果
- Android实现TextView跑马灯效果
- android用TextView实现跑马灯效果
- android TextView实现跑马灯效果
- android中TextView的文字实现动态效果,走马灯效果,闪烁效果
- Android拓展TextView 实现跑马灯效果
- Android之如何用TextView实现滚动字幕的效果【跑马灯】
- android textView实现跑马灯效果
- Android自定义TextView实现文字倾斜效果
- android---重写textview实现跑马灯
- Android开发实现TextView跑马灯效果