一般而言TextView内容长度太大,是会拆行显示的
布局限制时
使用android:singleLine="true"属性,可以只显示一行,但是不足无法显示部分带省略号。
使用android:ellipsize="marquee" 可以很好的解决这个问题,但仍然不会动
android:focusable="true"
android:focusableInTouchMode="true"//加上这两句属性,使TextView拿到页面焦点使其能够让文字循环移动
但是这种措施只针对有一个TextView要实现跑马灯的效果,因为其焦点只有一个,被第一拿了之后,
其他的就无法进行使用。
可以通过自定义一个MyTextView去继承TextView并改写
@Override
public boolean isFocused(){return true;}
使自定义的所有对象都可以取得Fo'cused,就能都是实现跑马灯效果了。
当然要设置其在某个点执行跑马灯也是可以的,这就得在java代码中去设置了。
<com.example.acher.textviewtext.MyTextView
android:id="@+id/textview1"
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
/>
<com.example.acher.textviewtext.MyTextView
android:id="@+id/textview2"
android:text="2222222222222222222222222222222222222222222222222222222222222222222"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
/>
public class MyTextView extends TextView {
public MyTextView(Context context) {
super(context);
}
public MyTextView(Context context,AttributeSet attrs,int defStyle){
super(context,attrs,defStyle);
}
public MyTextView(Context context,AttributeSet attrs)
{
super(context,attrs);
}
@Override
public boolean isFocused() {
return true;
}
}