1、定义textView标签的4个属性:
 android:singleLine="true"//使其只能单行
android:ellipsize="marquee"//去掉省略号
 android:focusable = "true"//使其循环
 android : focusableInTouchMode = "true"

为了永久的滚动,应该再加一个android:marqueeRepeatLimit="marquee_forever",这样就能一直在进行

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainLayout"
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.lj.chapter7.MainActivity"> <ImageButton
android:id="@+id/button_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="38dp"
android:background="#00000000"
android:longClickable="false"
android:src="@drawable/button1" /> <com.example.lj.chapter7.MarqueeTextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/button_one"
android:layout_centerHorizontal="true"
android:layout_marginTop="38dp"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:text="@string/simpleText" /> <ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="59dp"
android:src="@drawable/image1" /> <com.example.lj.chapter7.MarqueeTextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:text="@string/simpleText" />
</RelativeLayout>

2、自定义一个继承TextView的类:
 实现三个构造函数;
 复写isfocued方法,返回true(默认都有有焦点,平常只有一个有焦点在第一行上)

package com.example.lj.chapter7;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView; /**
* Created by LJ on 2016/8/13.
*/
public class MarqueeTextView extends TextView { public MarqueeTextView(Context context) {
super(context);
} public MarqueeTextView(Context context, AttributeSet attrs) {
super(context, attrs);
} public MarqueeTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
} @Override
public boolean isFocused() {
return true;
}
}

3、使用自定义的类,方法是用包名和自定义类名代替TextView(src下的包名+类名)

参考:http://www.imooc.com/video/4308

最新文章

  1. C语言程序设计第6堂作业
  2. URL传值特殊字符处理
  3. 【131031】jsp学习实例 (2013-10-31 15:29:28)
  4. linux驱动初探之杂项设备(控制两个GPIO口)
  5. php面向对象Object
  6. ThinkPHP第十三天(CONF_PATH、APP_PATH,UEditor用法)
  7. 用Bash脚本将Linux普通用户添加为系统管理员
  8. Linux Shell : Test命令参数解析
  9. &lt;未来世界的幸存者&gt; 读后感(现实篇和职业篇)
  10. 【java学习笔记】文件操作
  11. mariadb 压缩包gz安装方式
  12. 开发中的Date处理
  13. 5、MyBatis-parameterType 入参封装 Map 流程
  14. [20180612]删除bootstrap$记录无法启动.txt
  15. 【AngularJS】解决ng-if中的ng-model值无效的问题(转)
  16. 查看内核页表kernel_page_tables (aarch32)
  17. Spring3 MVC请求参数获取的几种方法[转载]
  18. https 的理解
  19. Collapsing Margin:外边距叠加
  20. SQL修改字段默认值、获取字段默认值

热门文章

  1. Oracle常用操作【自己的练习】
  2. awk 对简单文本处理试水
  3. SecureCRT 配置文件中 找密码
  4. hdu 4857 逆拓扑+大根堆(priority_queue)
  5. 用CSS3变形创建半圆形导航
  6. js判断手机的横竖屏调整样式
  7. 普元OA平台介绍
  8. BUPT复试专题—网络传输(2014网研)
  9. ivy在eclipse中的重新加载
  10. navicat-premium11.1.6 x64关键