[Android TV 按键响应]listview的textview跑马灯在鼠标控制下失效的问题

问题:遥控按键选中的选项有跑马灯效果,但是鼠标事件来说,没有跑马灯效果

解题过程:重写一个类继承textview,永远获取焦点,不行。即使我再OnhoverListener里面实现onHover并且对textview获取了焦点,但是仍旧不行

解决方法:最后重写一个类继承textview,永远获取焦点,并且对textview调用了setSelected(true)之后就可以了。

public class MarqueeTextView extends TextView {
    public MarqueeTextView(Context con) {
        super(con);
    }

    public MarqueeTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MarqueeTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean isFocused() {
        return true;
    }

    @Override
    protected void onFocusChanged(boolean focused, int direction,
            Rect previouslyFocusedRect) {
    }

}

    <com.jrm.localmm.ui.view.MarqueeTextView
        android:id="@+id/ListNameTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:gravity="left"
        android:layout_marginLeft="2dip"
        android:marqueeRepeatLimit="marquee_forever"
        android:singleLine="true"
        android:textColor="@android:color/white"
        android:textSize="15sp" >
    </com.jrm.localmm.ui.view.MarqueeTextView>

holder.settingOptionTextView.setSelected(true);

另外总结下AN TV下的鼠标,遥控按键事件:

首先对于selector而言,在TV下面只有遥控按键能够触发全部的事件:focus,selected,press

<?xml version="1.0" encoding="UTF-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">

	<!-- 无焦点状怿-->

	<item android:state_focused="false" android:state_selected="false" android:state_pressed="false"

		android:drawable="@android:color/transparent" />

	<item android:state_focused="false" android:state_selected="true" android:state_pressed="false"

		android:drawable="@drawable/list_foucs" />

	<!-- 焦点状怿-->	

	<item android:state_focused="true" android:state_selected="false" android:state_pressed="false"

		android:drawable="@drawable/list_foucs" />

	<item android:state_focused="true" android:state_selected="true" android:state_pressed="false"

		android:drawable="@drawable/list_foucs" />

	<!-- 按下状怿-->

	<item android:state_pressed="true" android:drawable="@drawable/list_foucs" />

</selector>

鼠标能触发的只要点击的时候的press事件。

至于在鼠标操控下要怎么模仿按键事件选择某个item之后,背景图像变化的话 ,只能间接通过设置item的背景图像来实现了

    //refresh the focus state of listview item
    public void refreshItemFocusState(int index) {
        // TODO Auto-generated method stub
        Log.d(TAG, "refreshItemFocusState index = "+index) ;
        currentSelectedItemView =  listView.getChildAt(index);
        if(isEnterListviewLocation){
            if(oldSelectedItemView != null)
                oldSelectedItemView.setBackgroundResource(R.drawable.button_normal) ;
            if(currentSelectedItemView != null)
                currentSelectedItemView.setBackgroundResource(R.drawable.list_foucs);
            oldSelectedItemView = currentSelectedItemView ;
        }
    }
时间: 2024-08-06 22:55:15

[Android TV 按键响应]listview的textview跑马灯在鼠标控制下失效的问题的相关文章

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

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

真正的TextView跑马灯

android自带的跑马灯是必须在有焦点的情况下才会滚动,一旦失去焦点跑马灯就会失去效果. 现在我的做法是自定义TextView 并重写isFocused和onFocusChanged方法,设置focused为true,这样TextView就可以始终获取到焦点 亲测可用! 1.自定义TextView: import android.content.Context; import android.graphics.Rect; import android.util.AttributeSet; im

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

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

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

Textview在Listview中实现跑马灯效果

textview添加属性: android:singleLine="true" 表示单行显示 android:ellipsize="marquee" 设置当文字过长时,该控件该如何显示.有如下值设置:”start”—–省略号显示在开头:”end”——省略号显示在结尾:”middle”—-省略号显示在中间:”marquee” ——以跑马灯的方式显示(动画横向移动) android:marqueeRepeatLimit="marquee_forever&quo

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