笔记6 TextView 跑马灯效果
来源:互联网 发布:一级域名免费注册 编辑:程序博客网 时间:2024/06/11 11:16
image - 想要获取图片通过src(图片不会变形) 想要设置背景用background(图片会变形)。
方法一:通过设置android:singleLine、android:ellipsis、android:focusable、android:focusableInTouchMode这四个属性来实现跑马灯效果
<TextView
android:id="@+id/tv1"
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/app_name1"/>
android:id="@+id/tv1"
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/app_name1"/>
方法二:自定义TextView,重写isFocused()方法,使全部的textview都可以一直获取焦点。
代码如下:
public class MarQueeTextView extends TextView {
public MarQueeTextView(Context context) {
super(context);
}
public MarQueeTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MarQueeTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public boolean isFocused() {
return true;//可以一直获取焦点。
}
}
public MarQueeTextView(Context context) {
super(context);
}
public MarQueeTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MarQueeTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public boolean isFocused() {
return true;//可以一直获取焦点。
}
}
布局文件如下:
<page.pay.third.com.marquee.MarQueeTextView
android:id="@+id/tv1"
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/app_name1"/>
android:id="@+id/tv1"
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/app_name1"/>
0 0
- 笔记6 TextView 跑马灯效果
- TextView跑马灯效果
- TextView跑马灯效果
- TextView跑马灯效果
- TextView跑马灯效果
- TextView跑马灯效果
- TextView跑马灯效果
- TextView 跑马灯效果
- TextView 跑马灯效果
- TextView跑马灯效果
- TextView跑马灯效果
- textview跑马灯效果
- textview跑马灯效果
- TextView跑马灯效果
- TextView跑马灯效果
- TextView跑马灯效果
- TextView跑马灯效果
- textview跑马灯效果
- Redis Cluster 3.0.5 集群实战
- 【OpenCV笔记 14】OpenCV图像增强方法直方图均衡化
- 226. Invert Binary Tree
- Android 使用Zxing实现二维码的生成,扫描
- spring aop 之获取 被切函数 参数及返回值
- 笔记6 TextView 跑马灯效果
- 打怪兽
- JMeter 介绍: 一个非常优秀的开源的性能测试工具。
- SOAP webserivce 和 RESTful webservice 对比及区别
- mesos+marathon环境简单搭建
- 死磕闲置交易的猎趣、闲鱼、转转们,拯救“剁手党”还差哪味猛药?
- spring AOP 之 获取 被切函数参数 被切函数返回值 以及 修改被切函数返回值
- poj 2631 1985 hdoj 2196 <树的直径>
- 基本算法学习