最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Android基于TextView不获取焦点实现跑马灯效果
时间:2022-06-25 23:29:30 编辑:袖梨 来源:一聚教程网
1. 写一个类继承TextView
| 代码如下 | 复制代码 |
|
packagecom.example.tt; importandroid.content.Context; importandroid.graphics.Rect; importandroid.util.AttributeSet; importandroid.widget.TextView; publicclassScrollingTextViewextendsTextView { publicScrollingTextView(Context context, AttributeSet attrs,intdefStyle) { super(context, attrs, defStyle); } publicScrollingTextView(Context context, AttributeSet attrs) { super(context, attrs); } publicScrollingTextView(Context context) { super(context); } @Override protectedvoidonFocusChanged(booleanfocused,intdirection, Rect previouslyFocusedRect) { if(focused) super.onFocusChanged(focused, direction, previouslyFocusedRect); } @Override publicvoidonWindowFocusChanged(booleanfocused) { if(focused) super.onWindowFocusChanged(focused); } @Override publicbooleanisFocused() { returntrue; } } |
|
2. xml 中增加属性
| 代码如下 | 复制代码 |
|
android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="80dip" android:layout_marginBottom="25dip" android:textSize="25sp" android:singleLine="true" android:textColor="@android:color/black" android:ellipsize="marquee" android:focusable="true" android:marqueeRepeatLimit="marquee_forever" android:focusableInTouchMode="true" android:scrollHorizontally="true" android:text="这才是真正的文字跑马灯效果,文字移动速度,文字移动方向,文字移动的样式,动画等等……" android:background="#2FFFFFFF"/> |
|
3. 在activity中声明
| 代码如下 | 复制代码 |
|
packagecom.example.tt; importandroid.os.Bundle; importandroid.app.Activity; importandroid.view.Menu; publicclassMainActivityextendsActivity { @Override publicvoidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } } |
|
相关文章
- 魔兽世界官方任务数据库查询入口-魔兽世界任务查询网址大全 01-05
- 虎牙网页版入口-虎牙直播官方登录入口 01-05
- minecraft网页版入口直达-Minecraft网页版官方地址 01-05
- 免会员电影软件哪个好用-真正免费看电影软件 01-05
- 悟空浏览器怎样快速打开网页-悟空浏览器电脑版免费在线观看 01-05
- 163邮箱网页登录入口官网-163邮箱手机版访问地址 01-05