您的位置:首页 > 其它

跑马灯效果

2016-03-03 17:48 225 查看
单个textview:

android:singleLine="true"
android:ellipsize="marquee"

android:focusable="true"

android:focusableInTouchMode="true"

多个Textview的话

A:

<TextView

android:id="@+id/tv1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:singleLine="true"

android:ellipsize="marquee"

android:focusable="true"

android:focusableInTouchMode="true"

android:text="@string/hello_world" />

B:

<TextView

android:layout_below="@id/tv1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:singleLine="true"

android:ellipsize="marquee"

android:layout_marginTop="20dp"

android:focusable="true"

android:focusableInTouchMode="true"

android:text="@string/hello_world" />

最后的结果发现,模拟器上只有第一行的Textview才能转动。

解决办法:

新建一个类,命名为MarqueeTextview.java

然后继承Textview,一共三个构造函数,要把他的构造函数全部展现出来【右击source,点击Generate constructors from superclass即可】

package com.example.marqueetextviewdemo;

import android.content.Context;

import android.util.AttributeSet;

import android.widget.TextView;

public class MatqueeTexxt extends TextView

{

public MatqueeTexxt(Context context, AttributeSet attrs)

{

super(context, attrs);

// TODO Auto-generated constructor stub

}

public MatqueeTexxt(Context context, AttributeSet attrs, int defStyle)

{

super(context, attrs, defStyle);

// TODO Auto-generated constructor stub

}

public MatqueeTexxt(Context context)

{

super(context);

// TODO Auto-generated constructor stub

}

@Override

public boolean isFocused()

{

// TODO Auto-generated method stub

return true;

}

}

<com.example.marqueetextviewdemo.MatqueeTexxt

android:id="@+id/tv1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:singleLine="true"

android:ellipsize="marquee"

android:focusable="true"

android:focusableInTouchMode="true"

android:text="@string/hello_world" />

<com.example.marqueetextviewdemo.MatqueeTexxt

android:layout_below="@id/tv1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:singleLine="true"

android:ellipsize="marquee"

android:layout_marginTop="20dp"

android:focusable="true"

android:focusableInTouchMode="true"

android:text="@string/hello_world" />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: