Marquee 跑马效果
16lz
2021-01-23
最近忽然看到了跑马效果,感觉还挺有意思的,但是查了网上好多例子感觉不够智能,感觉这个写的还不错,分享一下下
<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”
更多相关文章
- -Android各版本系统源代码下载
- 设置TextView文字居中,代码实现android:layout_gravity
- Android Studio中同步代码时报:Received status code 400 from se
- android java代码覆盖率
- Android对话框风格的Activity代码
- Android 删除指定文件代码
- Android摄像头视频帧数据测试代码
- Android 震动 和 停止 代码