android客户端学习-跑马灯效果
2016-04-16 16:54
351 查看
实现方法一:
1.在TextView中添加三个属性
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
效果如下:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="@string/hello_world"
/>
注意:(android:singleLine="true"设置TextView内容只能单行显示)该方法仅适用于页面布局比较简单,一个页面仅有一个跑马灯效果的需要时,但是一个页面如果有两个跑马灯,使用该方法,得到的结果往往只有一个TextView实现了跑马灯,另外一个TextView却没有实现,结果较为复杂页面的实现效果,可以使用方法二
实现方法二:
1.创建一个继承TextView的类,并且重载isFocused()方法,使其返回true
比如:
public class MarQueeText extends TextView {
public MarQueeText(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MarQueeText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public MarQueeText(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
@Override
public boolean isFocused() {
// 返回true
return true;
}
}
2.将xml文件中的TextView标签更换为自定义的类
如下:
<com.example.marqueetextdemo.MarQueeText
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="@string/hello_world" />
方法二便解决了一个页面需要多个跑马灯效果的需要
1.在TextView中添加三个属性
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
效果如下:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="@string/hello_world"
/>
注意:(android:singleLine="true"设置TextView内容只能单行显示)该方法仅适用于页面布局比较简单,一个页面仅有一个跑马灯效果的需要时,但是一个页面如果有两个跑马灯,使用该方法,得到的结果往往只有一个TextView实现了跑马灯,另外一个TextView却没有实现,结果较为复杂页面的实现效果,可以使用方法二
实现方法二:
1.创建一个继承TextView的类,并且重载isFocused()方法,使其返回true
比如:
public class MarQueeText extends TextView {
public MarQueeText(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MarQueeText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public MarQueeText(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
@Override
public boolean isFocused() {
// 返回true
return true;
}
}
2.将xml文件中的TextView标签更换为自定义的类
如下:
<com.example.marqueetextdemo.MarQueeText
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="@string/hello_world" />
方法二便解决了一个页面需要多个跑马灯效果的需要
相关文章推荐
- Android实现简单的自定义ListView
- android M 动态申请权限
- 重写View(一)弧线进度条
- android端发送验证码后倒计时程序
- Android ListView控件选中item项,并保持选中状态
- Android 在界面中显示以及输入文本信息 TextView和EditText
- 使用ScrollView属性fillViewport解决android布局不能撑满全屏的问题
- Activity的生命周期和启动模式
- Android手机计步器中加速度传感器熄屏时的侦听
- Arrayadapter
- Android——黑名单管理
- Android——事务
- android开发小技巧
- 值得你关注的Android6.0上的重要变化(一)
- android 5.0获取前台应用的包名的实现方法
- Android电池记录总结
- Android: 横竖屏切换时候重新走Activity生命周期
- Android官方开发文档Training系列课程中文版:管理音频播放之音频输出硬件的处理
- android中versionCode&versionName
- Android项目结构介绍