Android学习——跑马灯效果的实现
来源:互联网 发布:linux 目录覆盖 编辑:程序博客网 时间:2024/06/05 04:13
一、对一个TextView组件实现跑马灯效果
1.编辑activity_main.xml文件如下:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/button" /><!--android:singleLine="true"设置单行显示,否则会自动换行android:ellipsize="marquee"之后三个设置都是必须的android:focusable="true"android:focusableInTouchMode="true"--> <TextView android:id="@+id/textView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/text" android:singleLine="true" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true"/></LinearLayout>
2.该种方式在对多个组件进行跑马灯设置时只会有一个实现
二、对多个组件实现跑马灯效果
1.创建新类MyTextView扩展自TextView类,并覆盖TextView所有的构造方法及isFocused方法
package com.zyy.myapp;import android.content.Context;import android.util.AttributeSet;import android.widget.TextView;public class MyTextView extends TextView {public MyTextView(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);// TODO Auto-generated constructor stub}public MyTextView(Context context, AttributeSet attrs) {super(context, attrs);// TODO Auto-generated constructor stub}public MyTextView(Context context) {super(context);// TODO Auto-generated constructor stub}@Overridepublic boolean isFocused() {// 此处才是重点,的一种方式失败的原因就是不能设置第二个组件为焦点return true;}}
2.修改activity_main.xml文件如下:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/button" /><!--android:singleLine="true"设置单行显示,否则会自动换行android:ellipsize="marquee"之后三个设置都是必须的android:focusable="true"android:focusableInTouchMode="true"--> <TextView android:id="@+id/textView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/text" android:singleLine="true" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true"/><!-- 新添加的内容 --> <com.zyy.myapp.MyTextView android:id="@+id/textView2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/text" android:singleLine="true" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true"/> <com.zyy.myapp.MyTextView android:id="@+id/textView3" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/text" android:singleLine="true" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true"/></LinearLayout>
0 0
- Android学习——跑马灯效果的实现
- Android——TextView实现真正的跑马灯效果
- Android TextView 跑马灯效果的实现
- Android实现跑马灯效果的TextView
- Android 跑马灯效果的实现
- Android 跑马灯效果的实现
- Android——TextView实现跑马灯效果
- android实现跑马灯效果
- android实现跑马灯效果
- Android跑马灯效果实现
- android 实现跑马灯效果
- Android 跑马灯效果实现
- android实现跑马灯效果
- android跑马灯效果实现
- Android实现跑马灯效果
- Android跑马灯效果实现
- android实现跑马灯效果
- Android实现跑马灯效果
- 坚持#第70天~模拟短暂计划二维码完成&&tomcat
- codeforces 732F (桥)
- 常用SharedPreferences工具编写
- C语言代码6(判断两数组有无共同元素)
- setInterval(fn,delay)的工作原理以及小特点
- Android学习——跑马灯效果的实现
- Linux里vi介绍
- Spring MVC Rest Json,XML多视图解析 配置
- 《初入linux》--第十部分-设备使用与时间同步
- 练习 10.16
- iOS事件机制
- 20161018
- 【MATLAB】离散傅里叶变换DTFT和IDTFT
- 如何用export修改环境变量 以及 PATH与$PATH的区别