Android GridView嵌入ImageButton的问题
来源:互联网 发布:淘宝模版在线制作 编辑:程序博客网 时间:2024/05/29 14:50
项目中需要使用GridView的item中嵌入ImageButton。但是在嵌入之后发现,item将无法监听触屏消息。经过一段时间的研究发现是ImageButton在gridview的item之前优先获取了焦点。因此需要对焦点进行设置,具体的修改,如下:红色部分为增加后的属性设置,该设置最终解决了问题。
原始的xml文件如下:
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants"
>
<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="60dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:padding="10dp"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp"
android:descendantFocusability="afterDescendants"
/>
</LinearLayout>
griditem.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" >
</ImageView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/imageTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" >
</TextView>
<TextView
android:id="@+id/imagetext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" >
</TextView>
<ImageButton
android:id="@+id/imageAdd"
android:focusable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" >
</ImageButton>
</LinearLayout>
- Android GridView嵌入ImageButton的问题
- Android的ImageButton问题
- 关于用ImageButton删除GridView中的记录不成功的问题
- onInterceptTouchEvent解决GridView和ImageButton焦点共存的问题
- 解决android expandablelistview 里面嵌入gridview行数据重复问题
- ImageButton的坑 ImageButton 有问题
- 解决GridView中嵌入CheckBox事件无法响应的问题
- 解决GridView中嵌入CheckBox事件无法响应的问题
- Android-ImageButton的使用
- Android-ImageButton的使用
- Android-ImageButton的使用
- android imagebutton的使用
- Android:ListView中嵌入GridView,处理点击事件的冲突
- Android中使用selector动态改变imageView或ImageButton的背景和在GridView中应用
- Android中使用selector动态改变imageView或ImageButton的背景和在GridView中应用
- Android GridView 的item 使用 Button,imagebutton 等ui控件后,不能响应OnItemClick()事件
- Android开发中遇到ImageButton背景设置的问题
- ImageButton去边框的问题
- 对数据库中的数据进行分页处理的实现
- 9.windbg-!sym、.reload
- JSP于JS的交互
- ios图书翻页效果
- c++画图(2)-初步试验调用python
- Android GridView嵌入ImageButton的问题
- Android ListView 列表控件的简单使用
- 利用c#制作托盘程序,并禁止多个应用实例运行
- 2012年5月TIOBE编程语言排行榜发布:C继续领跑
- 同一个tomcat多个web应用共享session
- transform详解
- Android ApiDemos示例解析(1):创建ApiDemo示例
- swap_ranges详解
- 黑马程序员——反射