android textview 实现跑马灯效果
来源:互联网 发布:友价房产源码 编辑:程序博客网 时间:2024/06/11 17:09
跑马灯效果最重要的就是四个属性,分别是:
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"
控件的宽度,不一定是具体的值,可以是math_parent,如果想让textview中的文字滚动的话,那里面内容的长度肯定是要大于控件的长度的,不然滚动还有啥意思..
不过这样写的话,虽然很简单.但是有一个问题.就是只有在控件获得到焦点的时候才可以滚动.如果我们在textview控件的下方,添加一个edittext,直接就回看到用这四个属性修饰的.刚刚那个还可以滚动的textview现在竟然一动不动了.这个时候我们就要来对textview进行自定义了
package com.example.testscrotextview;import android.content.Context;import android.graphics.Rect;import android.util.AttributeSet;import android.widget.TextView;public class MyScrollTextView extends TextView {public MyScrollTextView(Context context, AttributeSet attrs) {super(context, attrs);}public MyScrollTextView(Context context) {super(context);}@Overridepublic boolean isFocused() {return true;//直接让他一直是获得焦点状态}@Overridepublic void onWindowFocusChanged(boolean hasWindowFocus) {if(hasWindowFocus)//获得焦点的时候,才执行一些操作super.onWindowFocusChanged(hasWindowFocus);}@Overrideprotected void onFocusChanged(boolean focused, int direction,Rect previouslyFocusedRect) {if(focused)//获得焦点的时候,才执行一些操作super.onFocusChanged(focused, direction, previouslyFocusedRect);}}
这个时候可以看到,只用四个修饰符修饰的textview一直不动,但是我们自定义的textview依然可以动,但是现在有一个尴尬,,就是当我们点击edittext或者让软键盘消失的话,我们自定义的textview就会重新开始滚动了..这点很尴尬...先留在这里吧..以后请教请教大神再..
1 0
- Android TextView跑马灯效果实现
- android textview跑马灯效果实现
- Android TextView实现跑马灯效果
- android TextView实现跑马灯效果
- android TextView实现跑马灯效果
- Android开发 TextView实现跑马灯效果
- android用TextView实现跑马灯效果
- Android TextView实现跑马灯效果
- Android TextView 跑马灯效果的实现
- android TextView实现跑马灯效果
- Android TextView实现跑马灯效果
- Android--TextView实现跑马灯效果
- Android开发:TextView实现跑马灯效果
- Android---14---TextView实现跑马灯效果
- Android TextView实现跑马灯效果。
- android textview 实现跑马灯效果
- Android下TextView实现跑马灯效果
- Android中长TextView实现跑马灯效果
- 相对布局
- 在mac OS上通过终端命令显示文件夹路径
- [C++设计模式] strategy 策略模式
- 使用PLSql连接Oracle时报错ORA-12541: TNS: 无监听程序
- Unity3D项目程序加密2——对dll进行混淆
- android textview 实现跑马灯效果
- 1005. Spell It Right (20)
- HDU 5282 Senior's String (两次dp LCS预处理)
- Android Studio SDK 更新方法
- 逻辑回归分类器(Logistic Regression Classifier)
- GRE写作必备句型
- Linux中link,unlink,close,fclose详解
- iOS开发:UITableView加载多张照片导致内存上涨的问题
- Unity3D项目程序加密1——在Unity3D里使用自己的dll