跑马灯效果
2016-03-03 17:48
225 查看
单个textview:
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
多个Textview的话
A:
<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/hello_world" />
B:
<TextView
android:layout_below="@id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:layout_marginTop="20dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="@string/hello_world" />
最后的结果发现,模拟器上只有第一行的Textview才能转动。
解决办法:
新建一个类,命名为MarqueeTextview.java
然后继承Textview,一共三个构造函数,要把他的构造函数全部展现出来【右击source,点击Generate constructors from superclass即可】
package com.example.marqueetextviewdemo;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
public class MatqueeTexxt extends TextView
{
public MatqueeTexxt(Context context, AttributeSet attrs)
{
super(context, attrs);
// TODO Auto-generated constructor stub
}
public MatqueeTexxt(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public MatqueeTexxt(Context context)
{
super(context);
// TODO Auto-generated constructor stub
}
@Override
public boolean isFocused()
{
// TODO Auto-generated method stub
return true;
}
}
<com.example.marqueetextviewdemo.MatqueeTexxt
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/hello_world" />
<com.example.marqueetextviewdemo.MatqueeTexxt
android:layout_below="@id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:layout_marginTop="20dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="@string/hello_world" />
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
多个Textview的话
A:
<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/hello_world" />
B:
<TextView
android:layout_below="@id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:layout_marginTop="20dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="@string/hello_world" />
最后的结果发现,模拟器上只有第一行的Textview才能转动。
解决办法:
新建一个类,命名为MarqueeTextview.java
然后继承Textview,一共三个构造函数,要把他的构造函数全部展现出来【右击source,点击Generate constructors from superclass即可】
package com.example.marqueetextviewdemo;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
public class MatqueeTexxt extends TextView
{
public MatqueeTexxt(Context context, AttributeSet attrs)
{
super(context, attrs);
// TODO Auto-generated constructor stub
}
public MatqueeTexxt(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public MatqueeTexxt(Context context)
{
super(context);
// TODO Auto-generated constructor stub
}
@Override
public boolean isFocused()
{
// TODO Auto-generated method stub
return true;
}
}
<com.example.marqueetextviewdemo.MatqueeTexxt
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/hello_world" />
<com.example.marqueetextviewdemo.MatqueeTexxt
android:layout_below="@id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:layout_marginTop="20dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="@string/hello_world" />
相关文章推荐
- 短信通信笔记
- 深度剖析移动电商的技术架构
- Nginx+CI出现404错误
- RabbitMQ (五)主题(Topic)
- maven项目出现如下错误,求指点;CoreException: Could not calculate build plan:
- RabbitMQ (四) 路由选择 (Routing)
- 关于html5--localStorage 储存json
- StretchDIBits 的使用
- RabbitMQ (三) 发布/订阅
- hdoj 1811 Rank of Tetris【拓扑排序 + 并查集】
- Visual Studio 编译项目失败,提示找不到文件
- (14)字符串
- 负载均衡 对应用机节点的故障检测
- Spring MVC 表单标签介绍
- snmp学习资料
- mysql备份:一,Xtrabackup
- RabbitMQ (二)工作队列
- Android一点 异常收集
- 系列文章--Node.js学习笔记系列
- 在C#中将String转换成Enum: