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

使用TextView实现跑马灯的效果的更多相关文章

  1. Android 高级UI设计笔记05:使用TextView实现跑马灯的效果

    1. 使用TextView属性实现跑马灯的效果: (1). 新建一个Android工程,命名为"MarqueeTextViewDemo",如下: (2). 来到activity_m ...

  2. android使用TextView实现跑马灯的效果(1)

    android使用TextView实现跑马灯的效果 1.activity_main.xml <?xml version="1.0" encoding="utf-8& ...

  3. Android:TextView文字跑马灯的效果实现

    解决TextView文字显示不全的问题. 简单设置跑马灯的效果: <TextView android:id="@+id/textView" android:layout_wi ...

  4. 在android中用跑马灯的效果显示textview

    大家好,在我们通常的android project中,通常需要用到textview这一个布局文件,并且对于这一个显示布局所需要的文本文字内容. 下面我们就来介绍一种方法来实现在android中用跑马灯 ...

  5. 浅谈TextView Ellipsize效果与Marquee跑马灯无效果问题

    说到TextView 效果,相信大家一定熟悉跑马灯. 先来看看 Ellipsize是什么,Ellipsize 从开发技术上翻译为省略效果.故名思议,就是当文本无法显示全部时,用什么效果来显示未显示的部 ...

  6. Android TextView实现跑马灯

    TextView实现跑马灯的效果:例子一: 这个例子可以解决给一个TextView实现跑马灯的效果,但是不能解决给所有的TextView实现跑马灯的效果. <TextView android:l ...

  7. 它们的定义TextView使之具有跑马灯的效果

    一.引入问题 使用通用textview快乐效应,焦点事件不启动滚动,button目前的焦点事件,但丑,因此,需要定制TextView 天生焦点 个textview FocusedTextView.ja ...

  8. Android界面(1) 使用TextView实现跑马灯效果

    方法一:(只能实现单个TextView的跑马灯效果)在TextView添加以下控件 android:singleLine="true"只能单行,超出的文字显示为"...& ...

  9. TextView的跑马灯效果实现

    TextView的跑马灯效果实现 问题描述 当文字内容过长,但是只允许显示一行时,可以将文字显示为跑马灯效果,即文字滚动显示. 代码实现 第一种方法实现 先查询TextView控件的属性,得到以下信息 ...

随机推荐

  1. R语言入门视频笔记--6--R函数之cat、format、switch函数

    一.cat 猫  怎么就变成一个输出函数了呢? cat  一个输出函数,功能和print有相同之处 我们一起比较看看 1.cat(“hellow world”)或cat('hellow world') ...

  2. 程序包com.sun.image.codec.jpeg不存在解决方法

    https://blog.csdn.net/u011627980/article/details/50436842

  3. android widgets控件

    1.TextView 类似,C#里的lable,显示一段文本 <TextView android:id="@+id/textView2" android:layout_wid ...

  4. Codeforces 514C Watto and Mechanism(字典树)

    题目链接  Watto and Mechanism 题意  给出$n$个串(相当于字典),然后给出$m$个询问. 每个询问以字符串的形式给出,你需要改变这个字符串中的任意一个字符 (必须改变且只能改变 ...

  5. word2013 交叉引用添加参考文献的尾注编号,通过查找 ^# 替换为 [^&] 的方式添加中括号,在进行“更新域”操作后,中括号消失。

    word2013 交叉引用添加的尾注编号,通过查找 ^# 替换为 [^&] 的方式添加中括号,用这个方法添加中括号很多次了,这次却出现问题:在进行“更新域”操作后,中括号消失.       详 ...

  6. Oracle 12c PDB和CDB全局用户权限问题

    Oracle12c版本中引入了新的CDB和PDB 默认登陆CDB后创建的用户为全局用户必须以c##开头 如果要访问CDB中的表,可以用GRANT命令赋权 但是上面的赋权并不会再PDB中生效 如果要这个 ...

  7. P3378 堆【模板】 洛谷

    https://www.luogu.org/problem/show?pid=3378 题目描述 如题,初始小根堆为空,我们需要支持以下3种操作: 操作1: 1 x 表示将x插入到堆中 操作2: 2 ...

  8. 使用Myeclipse + SVN + TaoCode 免费实现项目版本控制的详细教程

    通过Myeclipse + SVN插件 + TaoCOde可以省去代码仓库的租建:同时还可以很好的满足小团队之间敏捷开发的需求.接下来详细介绍整个搭建流程. 首先,介绍所用到的工具: 1,Myecli ...

  9. INAPP登陆调用的FB接口

    public function login_get (){ $this->load->helper ( 'auth' ); $redirectUrl = $this->input-& ...

  10. MCE----Machine-check exception

    http://en.wikipedia.org/wiki/Machine_Check_Exception Machine-check exception From Wikipedia, the fre ...