您的位置:首页 > 产品设计 > UI/UE

Marquee 跑马效果

2015-06-12 21:00 429 查看
最近忽然看到了跑马效果,感觉还挺有意思的,但是查了网上好多例子感觉不够智能,感觉这个写的还不错,分享一下下

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<com.imooc.marqueetextviewdemo2.MarqueeText
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"
android:text="@string/hello_world"/>
<com.imooc.marqueetextviewdemo2.MarqueeText
android:layout_below="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"
android:text="@string/hello_world" />

</RelativeLayout>


这里要说一下,有些代码,只是添加了

android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"


这四句代码,就可以就简单的实现了跑马的效果,但是,但是,但是!当你添加了两个TextView之后,你会发现,只有第一个会实现,就是因为这个Focuse的问题,具体是啥我就只能说的模糊,就不说了

package com.imooc.marqueetextviewdemo2;

public class MarqueeText extends TextView {

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
}

public MarqueeText(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public boolean isFocused()
{
return true;
}

}


但是 新建一个类之后再加上这几句代码,那就可以实现两个一起动,好几个一起动,很方便好用。

最后说 一定要在 activity上 控件里面加上包名 不然不好使

当我第一次使用的时候,会一直报错,找了半天发现包名不对,改正之后就好了。

还有一定要是设定 android:singleLine=”true”
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: