Android TextView跑马灯效果
来源:互联网 发布:淘宝网站功能 编辑:程序博客网 时间:2024/04/30 11:04
Android TextView跑马灯效果
效果图
TextView跑马灯
继承TextView重写isFocused方法还有配置singline属性
第一种方式:
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:background="#C0C0C0" android:orientation="vertical"> <!--android:ellipsize="marquee":定义跑马灯的效果--> <!--android:focusable="true":聚焦功能--> <!--android:focusableInTouchMode="true":在触屏手机获取焦点--> <!--android:marqueeRepeatLimit="marquee_forever":字体永远滚动--> <!--android:singleLine="true":单行显示--> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" android:marqueeRepeatLimit="marquee_forever" android:singleLine="true" android:text="没有一代人的青春是容易的。 每一代有每一代人的宿命、委屈、挣扎、奋斗, 没什么可抱怨的。——白岩松" android:textSize="30dp"/></LinearLayout>
第二种方式:
自定义TextView
/** * 自定义TextView实现跑马灯效果 * Created by baochen on 2016/1/25. */public class MyTextView extends TextView { public MyTextView(Context context) { super(context); } public MyTextView(Context context, AttributeSet attrs) { super(context, attrs); } public MyTextView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } //重写isFocused方法,让其一直返回true public boolean isFocused() { return true; }}
重点:
//重写isFocused方法,让其一直返回truepublic boolean isFocused() { return true; }
此时的XML布局
<com.example.chenxiaoyang.reuselayout.MyTextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="marquee" android:singleLine="true" android:text="没有一代人的青春是容易的。 每一代有每一代人的宿命、委屈、挣扎、奋斗, 没什么可抱怨的。——白岩松" android:textSize="30dp"/>
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 TextView跑马灯效果
- android textView跑马灯效果
- Android TextView 跑马灯效果
- Android TextView跑马灯效果
- android textview 跑马灯效果
- Comparable & Comparator用法
- 516. Longest Palindromic Subsequence
- LeetCode 279. Perfect Squares
- 为什么要有Mycat---Mycat的前世今生
- 实现搜索框提示功能的方法
- Android TextView跑马灯效果
- 次小生成树
- linux常用命令(二)
- [编程题]序列和
- Udacity安卓入门第一个项目-商家信息应用
- 如何为python添加机器学习库:numpy,pandas,matplotlib
- 邮件
- ind the integer A such that pow(A,N) is as close as possible to B
- mac下java web项目搭建eclipse+Tomcat