2019独角兽企业重金招聘Python工程师标准>>>
1.当只有1个textview需要滚动显示效果的时候,我们只需要实现以下属性
<!--singleLine -- 单行 高版本api使用maxLines=1代替 -->
<!--ellipsize -- 去掉多余省略号-->
<!--focusable -- 获取焦点-->
<!--focusableInTouchMode -- 非触摸设备获取焦点-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是一个长Text,我是一个长Text,我是一个长Text,我是一个长Text,我是一个长Text,我是一个长Text,我是一个长Text"
android:textSize="24sp"
android:singleLine="true"
android:maxLines="1"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:id="@+id/textView1" />
2.当多个textview需要,我们就要新起一个扩展textview的类,同时改变其属性方法,使其获取标准
<com.example.ling.myapplication.MarqueeText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是一个长Text,我是一个长Text,我是一个长Text,我是一个长Text,我是一个长Text,我是一个长Text,我是一个长Text"
android:textSize="24sp"
android:singleLine="true"
android:maxLines="1"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:id="@+id/textView2"
android:layout_below="@+id/textView1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
/>
public class MarqueeText extends TextView {
public MarqueeText(Context context) {
super(context);
}
public MarqueeText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MarqueeText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
//判断该textview是否获得焦点
@Override
public boolean isFocused() {
return true;
}
}