Android实现多个跑马灯效果,多个文本框TextView的跑马灯
来源:互联网 发布:mac炉石盒子记牌器 编辑:程序博客网 时间:2024/04/28 02:20
转自:http://blog.csdn.net/aminfo/article/details/7558550
转处:http://wenku.baidu.com/link?url=NQ_JGiFDA_bsM61XVwAltf_TkCdtJ8tIoij3kQppYqRDwlXyFZt2PwR01kHTk-fO7it15m5G7N6D-CLJCmIToP4nOfzlxHrkf3XHgYZlUzu
package com.example.textviewdemo;import android.content.Context;import android.graphics.Rect;import android.util.AttributeSet;import android.widget.TextView;public class Marquee extends TextView {public Marquee(Context context, AttributeSet attrs) {super(context, attrs);}@Overrideprotected void onFocusChanged(boolean focused, int direction,Rect previouslyFocusedRect) {if (focused)super.onFocusChanged(focused, direction, previouslyFocusedRect);}@Overridepublic void onWindowFocusChanged(boolean hasWindowFocus) {if (hasWindowFocus)super.onWindowFocusChanged(hasWindowFocus);}@Overridepublic boolean isFocused() {return true;}}
<LinearLayout 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="com.example.textviewdemo.MainActivity" android:orientation="vertical"> <TextView android:id="@+id/tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" android:textSize="20sp" android:textColor="#FF0000" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:autoLink="all" android:text="www.baidu.com\n电话:18610331796" android:textSize="20sp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20sp"android:text="泡泡花泡花花妈妈爸爸天天天使我们的爱,过了就不会来" android:singleLine="true" android:clickable="true" android:focusable="true" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:focusableInTouchMode="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="车诚俊,韩静书,李光洙,刘在石,大神,金钏国,哈哈,GARY,智孝,我的野蛮王妃,宫,天国的阶梯" android:textSize="20sp" android:singleLine="true" android:clickable="true" android:focusable="true" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:focusableInTouchMode="true" /> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> <com.example.textviewdemo.Marquee android:id="@+id/pmd1" android:layout_width="200dip" android:layout_height="wrap_content" android:layout_marginLeft="10dip" android:layout_marginRight="10dip" android:clickable="true" android:ellipsize="marquee" android:focusable="false" android:singleLine="true" android:focusableInTouchMode="true" android:marqueeRepeatLimit="marquee_forever" android:scrollHorizontally="true" android:text="跑马灯文字1跑马灯文字1跑马灯文字1跑马灯文字1" /> <com.example.textviewdemo.Marquee android:id="@+id/pmd2" android:layout_width="200dip" android:layout_height="wrap_content" android:layout_marginLeft="10dip" android:layout_marginRight="10dip" android:clickable="true" android:ellipsize="marquee" android:focusable="true" android:singleLine="true" android:focusableInTouchMode="true" android:marqueeRepeatLimit="marquee_forever" android:scrollHorizontally="true" android:text="这里是第2个跑马灯噢!这里是第2个跑马灯噢!这里是第2个跑马灯噢!" /> <com.example.textviewdemo.Marquee android:id="@+id/pmd3" android:layout_width="200dip" android:layout_height="wrap_content" android:layout_marginLeft="10dip" android:layout_marginRight="10dip" android:clickable="true" android:ellipsize="marquee" android:focusable="true" android:singleLine="true" android:focusableInTouchMode="true" android:marqueeRepeatLimit="marquee_forever" android:scrollHorizontally="true" android:text="》》》第3个跑马灯》》》第3个跑马灯》》》第3个跑马灯" /> </LinearLayout> </LinearLayout>
备注:如果重写一个类的话,在xml中需要指定该类
<span style="font-size:18px;"><com.example.textviewdemo.Marquee android:id="@+id/pmd3" </span>
onFocusChanged方法
继承自View类,该方法是焦点改变的回调方法,当某个控件重写了该方法,当焦点发生变化时,会自动调用该方法来处理焦点改变的事件
onFocusChanged(boolean focused, int direction,Rect previouslyFocusedRect)
其中focused:表示触发该事件的View是否获得了焦点,当该控件获得焦点时,focused等于true,否则等于false;
direction:表示焦点移动的方向,用数值表示
previouslyFocusedRect:表示在触发事件的View的坐票系中,前一个获得焦点的矩形区域,即表示焦点是从哪里来的,如果不可用则为null;
onWindowFocusChanged方法
继承自View类,可能 直接获取到手机屏幕的高度和宽度,当Activity的当前window获得或失去焦点时会被回调方法,当回调了这个方法时表示Activity是完全对用户可见的,当对话框弹出/消失及Activity新创建及回退等都 会调用此方法
0 0
- Android实现多个跑马灯效果,多个文本框TextView的跑马灯
- Android实现多个跑马灯效果,多个文本框TextView的跑马灯
- 多个TextView实现跑马灯效果
- 多个TextView跑马灯效果实现
- Android实现多个TextView同时显示跑马灯效果
- Android实现多个TextView同时显示跑马灯效果
- Android实现多个TextView同时显示跑马灯效果
- Android实现多个TextView同时显示跑马灯效果
- Android-多个TextView实现跑马灯效果
- 多个TextView跑马灯效果
- 多个TextView 跑马灯效果
- android 跑马灯效果的基本实现以及自定义实现一个界面多个跑马灯效果
- 使同一界面的多个textview实现跑马灯效果
- Android TextView 跑马灯效果的实现
- Android实现跑马灯效果的TextView
- Android自学笔记之 多个TextView跑马灯的实现
- 当多个TextView要使用跑马灯的效果时需要注意的问题
- 多个控件跑马灯效果
- ElasticSearch入门介绍之会当凌绝顶(一)
- winform 项目应用程序有多个入口点
- PC与开发板之间最简单快速的文件传输方式
- 10个有用的php代码实例
- Text Kit学习(入门和进阶)
- Android实现多个跑马灯效果,多个文本框TextView的跑马灯
- java参数传递(超经典)
- django cpu监控之六-----使用COM组件获取CPU数据
- linux驱动之分离分层的概念
- 搭pl/proxy集群
- Android布局优化
- vs2012 boost库安装配置
- 大陆下载android 源码
- C++ 结构体(四)