android 跑马灯实现
必须设置这2个,否则没效果!
android:singleLine="true"
android:focusableInTouchMode="true"
网上有的根本不能实现效果。莫非和版本有关?
另外:可参考http://www.eoeandroid.com/forum.php?mod=viewthread&tid=165922&reltid=183394&pre_thread_id=0&pre_pos=2&ext=
(文本框内容文本的“跑马灯”效果在有些地方很有用。通过搜索学习,附件的源码把“跑马灯”的几种做法归纳在一起,供大家参考!!!!!!)
下面是我的简单实现
XML定义:
默认的TextView
<TextView
android:id="@+id/marqueebyxml"
android:layout_width="5dip"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:layout_marginLeft="10dip"
android:focusableInTouchMode="true"
android:text="这是通过XML文件设置的效果!" />
自定义:
<com.wletv.MarqueeText
android:id="@+id/AMTV1"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_marginLeft="80dip"
android:textSize="25sp"
android:textColor="@android:color/black"
android:lines="1"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:marqueeRepeatLimit="marquee_forever"
android:ellipsize="marquee"
android:background="#2FFFFFFF"
android:singleLine="true"
android:text="这才是真正的文字跑马灯效果,文字移动速度,文字移动方向,文字移动的样式,动画等等……"
/>
package com.wletv;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.TextView;
public class MarqueeText extends TextView {
public MarqueeText(Context con) {
super(con);
}
public MarqueeText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MarqueeText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean isFocused() {
return true;
}
@Override
protected void onFocusChanged(boolean focused, int direction,
Rect previouslyFocusedRect) {
}
}
更多相关文章
- 2011.07.05(3)——— android PopupWindow 以及activity切换的动
- 收集android上开源的酷炫的交互动画和视觉效果:Interactive-anima
- android textview 利用空格实现文字均匀分布
- android超炫button按钮动画效果
- android实现图片模糊背景效果
- Android 为图片添加文字水印
- Android MenuItem 设置文字颜色-TextColor的设置
- 自定义垂直文字view
- Android 系统自带Activity效果