列表视图问题
我对 ListView 组件有一个小问题,当我单击一行时,应用程序捕获触摸事件,但该行没有聚焦!
有什么想法吗?
这是 listview 的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/categoriestab_main"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFFFF"
>
<ListView
android:id="@+id/categorieslist"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFFFF"
android:cacheColorHint="#FFFFFFFF"
/>
</LinearLayout>
这是单行的布局:
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFFFF"
>
<ImageView
android:id="@+id/category_image"
android:layout_width="60dp"
android:layout_height="40dp"
android:src="@drawable/no_foto"
/>
<TextView
style="@style/categories_title"
android:id="@+id/category_name"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:singleLine="true"
android:layout_toRightOf="@id/category_image"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
/>
</RelativeLayout>
I have an little issues with an ListView component, when I click on a row the Application capture the touch event but but the row isn't focused!
Any ideas?
This is the XML of listview :
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/categoriestab_main"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFFFF"
>
<ListView
android:id="@+id/categorieslist"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFFFF"
android:cacheColorHint="#FFFFFFFF"
/>
</LinearLayout>
And this is a layout of a single row:
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFFFF"
>
<ImageView
android:id="@+id/category_image"
android:layout_width="60dp"
android:layout_height="40dp"
android:src="@drawable/no_foto"
/>
<TextView
style="@style/categories_title"
android:id="@+id/category_name"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:singleLine="true"
android:layout_toRightOf="@id/category_image"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
/>
</RelativeLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的RelativeLayout 上,删除您添加的
背景
,而只使用ListView 上的背景颜色。该背景颜色阻碍了点击效果。On your RelativeLayout, remove the
background
you have added and instead just have the background color on the ListView. That background color is blocking the click effect.