安卓定制的ListView与ImageButton的是没有得到焦点 [英] Android custom ListView with ImageButton is not getting focus
问题描述
我开发的Android电视的应用程序。我有一个列表视图
与的ImageButton
+ 的TextView
译文]儿童。由于电视没有考虑触摸事件,但使用D-PAD或轨迹球遥控我得专注于所有的可点击的项目,以便用户知道在哪里的焦点。但问题是,我可以专注于列表行,如果我想补充
安卓descendantFocusability =blocksDescendants
在自定义列表列布局,但的ImageButton
列表行中不会得到焦点。
如果我删除上述code,那么的ImageButton
获得焦点,但我不能单击列表行。
此外,我添加<一个href="http://developer.android.com/reference/android/widget/ListView.html#setItemsCanFocus%28boolean%29"><$c$c>setItemsCanFocus$c$c>我的的ListView
,但没有运气,没有什么改变。
我看了很多文件,但我无法找到这个问题的一个正确的答案。我想关注这两个表行以及的ImageButton
。是否有可能,如果任何人知道,请帮我...
我得专注于所有的可点击的项目,以便用户知道在哪里的焦点。但问题是,我可以专注于列表行,如果我想补充
查看越来越挂断由于内部排文件的多个视图,以获得点击你要添加更多的属性,以行XML的主布局。
安卓descendantFocusability =blocksDescendants
但是,当我写上面的属性然后我不能集中精力的ImageButton这是在我行的文件。
我只是想一个办法获得了这幅以获得foucus 的ImageButton
以及对列表视图
。
要获得ImageButton的焦点:的
- 创建一个选择文件。
- 在应用上的ImageButton。
- 新增
机器人:focusableInTouchMode =真正的
来的ImageButton
要重点关注列表视图:的
- 添加
机器人:descendantFocusability =blocksDescendants
来行内XML主要布局
现在,当你点击你的ImageButton将重点与你的愿望颜色,甚至是将重点放在列表视图中点击了。
Selecotor.xml 的
&LT; XML版本=1.0编码=UTF-8&GT?;
&LT;选择
的xmlns:机器人=http://schemas.android.com/apk/res/android
&GT;
&LT;项目
机器人:STATE_ pressed =真
机器人:可绘制=@机器人:彩色/透明
/&GT; &LT; - !pressed - &GT;
&LT;项目
机器人:state_focused =真
机器人:可绘制=@机器人:彩色/ darker_gray
/&GT; &LT;! - 集中 - &GT;
&LT;项目
机器人:可绘制=@机器人:可绘制/ btn_star
/&GT; &LT;! - 默认 - &GT;
&LT; /选择器&GT;
经过测试,在S3模拟器,效果很好。
I am developing an app for android TV. I have a listview
with an ImageButton
+ Textview
s as children. As TV does not take touch events but uses D-PAD or trackball remote I have to get focus on all clickable items so that user knows where the focus is. But the problem is I can get focus on list row if I add
android:descendantFocusability="blocksDescendants"
in the custom list row layout but ImageButton
in the list row will not get focus.
And if I remove above code then ImageButton
gets focus but I can't click list row.
Also I added setItemsCanFocus
for my ListView
but no luck, nothing changed.
I read many documents but i could not find a proper answer for this problem. I want focus on both List row as well as ImageButton
. Is it possible, if any one knows please help me...
I have to get focus on all clickable items so that user knows where the focus is. But the problem is I can get focus on list row if I add
View getting hang up due to multiple views inside row file, to get click You have to add one more property to your main layout of row xml.
android:descendantFocusability="blocksDescendants
But when I write above property then I'm not able to focus ImageButton which is in my row file.
I just tried one way to acheive to get foucus on ImageButton
as well as on listview
.
To get focus on ImageButton:
- Create one selector file.
- Applied on Imagebutton.
- Added
android:focusableInTouchMode="true"
to ImageButton.
To get focus on Listview:
- Add
android:descendantFocusability="blocksDescendants
to main-layout within row xml.
Now when you click on your ImageButton it will focus with your desire color even it will focus on listview click too.
Selecotor.xml
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:state_pressed="true"
android:drawable="@android:color/transparent"
/> <!-- pressed -->
<item
android:state_focused="true"
android:drawable="@android:color/darker_gray"
/> <!-- focused -->
<item
android:drawable="@android:drawable/btn_star"
/> <!-- default -->
</selector>
Tested in S3 emulator, works well.
这篇关于安卓定制的ListView与ImageButton的是没有得到焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!