真正的TextView跑马灯

android自带的跑马灯是必须在有焦点的情况下才会滚动,一旦失去焦点跑马灯就会失去效果。

现在我的做法是自定义TextView 并重写isFocused和onFocusChanged方法,设置focused为true,这样TextView就可以始终获取到焦点

亲测可用!

1。自定义TextView:

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.ViewDebug.ExportedProperty;
import android.widget.TextView;

public class ScrollForeverTextView extends TextView
{

    public ScrollForeverTextView(Context context)
    {
        super(context);
        // TODO Auto-generated constructor stub
    }

    public ScrollForeverTextView(Context context, AttributeSet attrs,
            int defStyle)
    {
        super(context, attrs, defStyle);
        // TODO Auto-generated constructor stub
    }

    public ScrollForeverTextView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

    @Override
    @ExportedProperty(category = "focus")
    public boolean isFocused()
    {
        // TODO Auto-generated method stub
        return true;//重点
    }

    @Override
    protected void onFocusChanged(boolean focused, int direction,
            Rect previouslyFocusedRect)
    {
        // TODO Auto-generated method stub
        super.onFocusChanged(true, direction, previouslyFocusedRect);//重点
    }
}

2。xml中引用:

           <。。。.view.ScrollForeverTextView
                android:id="@+id/title"
                style="@style/shadow5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:ellipsize="marquee"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:marqueeRepeatLimit="marquee_forever"
                android:maxEms="8"
                android:scrollHorizontally="true"
                android:singleLine="true"
                android:text=""
                android:textColor="@color/white"
                android:textSize="@dimen/text_size_18" />

真正的TextView跑马灯,布布扣,bubuko.com

时间: 2024-08-05 23:38:18

真正的TextView跑马灯的相关文章

Android TextView跑马灯效果

TextView跑马灯简单效果 <!--简单示例--> <TextView android:text="@string/longWord" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView1" android:ellipsize="marquee&quo

TextView跑马灯

TextView跑马灯 textView跑马灯实现:1.定义textView标签的4个属性:android:singleLine="true"//使其只能单行android:ellipsize="marquee"//去掉省略号android:focusable = "true"//使其循环android : focusableInTouchMode = "true"2.自定义类继承TextView:实现三个构造函数:复写isf

Third Day:正式编程第三天,学习实践内容TextView跑马灯、AutoCompleteTextView、multiAutoCompleteTextView以及ToggleButton、checkedBox、RadioButton等相关实践

2.针对Focused的TextView跑马灯(文字较多一行无法显示)效果 针对单个TextView的跑马灯效果,可直接在TextView控件参数中添加三个属性: android:singleLine="true"(一行显示会有省略号) android:ellipsize="marquee"(一行显示无省略号) android:focusable="true" android:focusableInTouchMode="true&quo

Android自学笔记之 多个TextView跑马灯的实现

textView跑马灯实现: 1.定义textView标签的4个属性: android:singleLine="true"//使其只能单行 android:ellipsize="marquee"//去掉省略号 android:focusable = "true"//使其循环 android : focusableInTouchMode = "true" 这样一个TextVIew就实现了跑马灯效果了,但是如果再用相同的写法写第二

Android TextView跑马灯

1 <TextView 2 android:layout_width="fill_parent" 3 android:layout_height="wrap_content" 4 android:layout_margin="20dp" 5 android:ellipsize="marquee" 6 android:focusable="true" 7 android:focusableInTouch

android在Gridview实现Textview跑马灯效果

默认是下面的属性添加TextView中: android:ellipsize="marquee" android:focusableInTouchMode="true" android:gravity="center" android:marqueeRepeatLimit="marquee_forever" android:scrollHorizontally="true" android:singleLi

Android textview 跑马灯 要加的属性

<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="@android:color/white"  android:ellipsize="marquee"  android:focusable="true" android:singleLine = &q

Android自定义之TextView跑马灯的监听

TextView都有跑马灯的效果,如果说让你去监听跑马灯效果的执行,我觉得这个需求有点二了,但是也要实现. 思路: 1.自定义View  继承TextView   这种方法过于麻烦,只是监听一个跑马灯而已. 2.自定义SPan.简单好用,扩展TextView的功能. 关键代码如下: @Override public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, in

关于有多个Fragment中的textview跑马灯问题

============问题描述============ 一个activity里面有多个Fragment,1,2,3,4 其中fragment1中有2个textview,在第一次启动fragment1的时候跑马灯能正常跑马; 当跳转到其他fragment后,再回到fragment1的时候,跑马灯已经不跑马了? 关于这个是textview的焦点问题吗? 求大神解答,,,求大神解决.... ============解决方案1============ 应该不是,应该是生命周期的问题,你把跑马灯别写在o