android TextView实现跑马灯效果
来源:互联网 发布:算法设计与分析课件 编辑:程序博客网 时间:2024/06/09 22:55
TextView自带了跑马灯功能,只要把它的ellipsize属性设置为marquee就可以了。但有个前提,就是TextView要处于被选中状态才能有效果,看到这,我们就很自然的自定义一个控件,写出以下代码
public
class
MarqueeTextView
extends
TextView {
public
MarqueeTextView(Context con) {
super
(con);
}
public
MarqueeTextView(Context context, AttributeSet attrs) {
super
(context, attrs);
}
public
MarqueeTextView(Context context, AttributeSet attrs,
int
defStyle) {
super
(context, attrs, defStyle);
}
@Override
public
boolean
isFocused() {
// TODO Auto-generated method stub
if
(getEditableText().equals(TruncateAt.MARQUEE)){
return
true
;
}
return
super
.isFocused();
}
}
<linearlayout android:layout_height=
"match_parent"
android:layout_width=
"match_parent"
android:orientation=
"vertical"
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
>
<framelayout android:background=
"#39ac69"
android:id=
"@+id/titlebar_layout"
android:layout_height=
"wrap_content"
android:layout_width=
"match_parent"
>
<linearlayout android:background=
"#ffffff"
android:gravity=
"center_vertical"
android:layout_height=
"50dp"
android:layout_width=
"match_parent"
android:orientation=
"horizontal"
>
<imageview android:id=
"@+id/home_location_iv"
android:layout_height=
"27dp"
android:layout_marginleft=
"10dp"
android:layout_width=
"25dp"
android:scaletype=
"fitXY"
android:src=
"@drawable/icon_place"
>
<com.lxj.marqueetextview.marqueetextview
android:ellipsize=
"marquee"
android:focusable=
"true"
android:focusableintouchmode=
"true"
android:gravity=
"center"
android:id=
"@+id/home_location_tv"
android:layout_height=
"wrap_content"
android:layout_marginleft=
"10dp"
android:layout_marginright=
"10dp"
android:layout_weight=
"1"
android:layout_width=
"0dp"
android:marqueerepeatlimit=
"marquee_forever"
android:scrollhorizontally=
"true"
android:singleline=
"true"
<!--此处改为maxLine跑马灯效果就消失 具体原因不太清除-->android:text=
"正在定位..."
android:textcolor=
"#39ac69"
android:textsize=
"18sp"
>
<imageview android:id=
"@+id/home_search_iv"
android:layout_height=
"27dp"
android:layout_marginright=
"10dp"
android:layout_width=
"25dp"
android:scaletype=
"fitXY"
android:src=
"@drawable/icon_place"
>
</imageview>
</com.lxj.marqueetextview.marqueetextview>
</imageview>
</linearlayout>
</framelayout>
</linearlayout>
阅读全文
0 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实现跑马灯效果
- Android USB Create Connection 完整过程
- QQ第三方登陆回调处理
- nodejs Assignment to constant variable
- 字符串-leetcode 72 Edit Distance
- Jfinal调用存储过程方法
- android TextView实现跑马灯效果
- fig14-09
- 高清时代4K H.265/HEVC来临---OTT/IPTV直播系统大发展
- 域名劫持原理及实现
- cocos ide 新建项目无响应及read nil 报错解决
- 运行程序,提示内存错误
- 触发器简单实例讲解
- CartoDB source example——CartoDB数据源案例
- MFC中CFileDialog的用法