专注于GridView布局

| 在我的Android应用中,我有一个带有一组按钮的GridView布局。问题是,我无法正确设置按钮上的焦点(我的意思是光标,由Android设备上的操纵杆控制)。我可以用一张图片描述我的问题: 我使用LayoutInflater在BaseAdapter中的代码中将Buttons动态设置为GridView。在代码中,我设置了按钮的文本,图像(CompoundDrawable)和背景颜色,因为我的按钮就像一个复选框一样工作(蓝色背景表示已选中)。 似乎程序正在关注网格区域而不是按钮本身。我的意思是类似表格的单元格而不是表格中的按钮。因为焦点颜色是默认(绿色),但是我在选择器中设置了蓝色。焦点印刷也不起作用。而且焦点显然在按钮后面,超出了按钮的范围。有人可以帮我解决这个麻烦吗?我的XML布局代码: main.xml:
...
<GridView
    android:id=\"@+id/channels\"
    android:layout_width=\"fill_parent\"
    android:layout_height=\"fill_parent\"
    android:padding=\"6dip\"
    android:verticalSpacing=\"10dip\"
    android:horizontalSpacing=\"10dip\"
    android:numColumns=\"auto_fit\"
    android:columnWidth=\"60dip\"
    android:stretchMode=\"columnWidth\"
    android:gravity=\"center\"        
    android:background=\"@color/container_main\">
</GridView>
...
channel.xml:
<Button
    android:id=\"@+id/channel\"
    android:layout_height=\"fill_parent\"
    android:layout_width=\"fill_parent\"
    android:gravity=\"center_horizontal\"         
    android:background=\"@color/willBeSetInAdapter\" <!-- white/blue/darkblue focus background -->
    android:drawableTop=\"@drawable/willBeSetInAdapter\" <!-- icon -->
    android:drawablePadding=\"0dip\"         
    android:text=\"WillBeSetInAdapter\" <!-- label text -->
    android:textColor=\"@color/text_container_main\"
    android:textSize=\"12sp\" 
    android:focusable=\"true\" 
    android:focusableInTouchMode=\"false\">
</Button>
我尝试在Button和GridView中设置焦点参数,并尝试了很多方法,但是不幸的是,它仍然不起作用:(     
已邀请:
为GridView设置android:descendantFocusability = \“ afterDescendants \”解决了我的问题。因为程序专注于网格字段,而不是按钮本身。使用DescendantFocusability参数,我禁止聚焦网格字段,并且只允许聚焦按钮。     
您是否尝试过为
GridView
设置
android:drawSelectorOnTop=\"true\"
?     

要回复问题请先登录注册