---
title: "android  marquee textview 走马灯效果"
author: "dkmeteor"
date: "2012-02-27T12:04:55Z"
tags: []
categories: ["移动开发"]
slug: "android-marquee-textview"
draft: false
lastmod: "2012-02-27T12:04:55Z"
id: 1425376
url: "https://dkmeteor.iteye.com/blog/1425376"
---

网上查的全都不能用。还是自己试验出来的。。。

 

测试机版本：4.0.3

 

网上有文章说要加 addStatesFromChildren

实测：加不加都能正常滚动

 

android:focusable="true"

实测：必须在xml里添加。在程序中使用tv.setFocusable(true);不能滚动

 

 

 

 

 

&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
android:layout\_width="fill\_parent"  
android:layout\_height="fill\_parent"  
android:orientation="vertical"  
android:addStatesFromChildren="true"  
&gt;

     
&lt;TextView  
android:id="@+id/tv"  
android:layout\_width="100px"  
android:layout\_height="wrap\_content"  
android:text="11adshfkalhafklajfhkadjfhakjfhdjkfhadfjkhasdfhasdfjkhasdjkfhsdakfhasdjkfhasdkfhsajkdfhsdfhsadfkjhsaf"  
android:singleLine="true"  
android:marqueeRepeatLimit="marquee\_forever"  
android:ellipsize="marquee"  
android:focusableInTouchMode="true"  
android:scrollHorizontally="true"  
android:focusable="true"  
/&gt;  
&lt;Button

android:layout\_width="100px"  
android:layout\_height="wrap\_content"  
android:text="sad"  
/&gt;  
&lt;/LinearLayout&gt;

 

 

 

下面加的那个Button时为了测试焦点问题添加的

点击Button对 滚动 无影响  （点击时Button获取焦点）