在ListView的宽度可点击区域的W / onListItemClick [英] Width of clickable area in ListView w/ onListItemClick
问题描述
我试图让一个ListView可点击我的列表项。目前,他们可以点击(见我的截图),但他们只是文字占用的矩形中单击。
I'm trying to get my list items in a ListView clickable. At the moment they are clickable (see my screenshot) but they're only clickable within the rectangle the text takes up.
我用保护无效onListItemClick(ListView的L,视图V,INT位置,长的id){
对于可点击列表中的项目。
I'm using protected void onListItemClick(ListView l, View v, int position, long id) {
for the clickable list items.
下面是我的list.xml:
Here is my list.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ListView android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_favorites"/>
和我row.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView android:id="@+id/artist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/songtitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_alignParentRight="true"/>
<TextView android:id="@+id/album"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_alignParentRight="true"/>
<TextView android:id="@+id/playtime"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_alignParentRight="true"/>
<TextView android:id="@+id/playlistnum"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentRight="true"
android:visibility="gone" />
</LinearLayout>
和这里的截图的例子: (新用户不得发表图片...叽...有一个超链接!)
And here's the screenshot example: (New users aren't allowed to post images... grumble... have a hyperlink!)
在list.xml,在ListView有机器人:layout_width =FILL_PARENT,因此它应该是在屏幕的整个宽度。 (所有的row.xml的项目也WIDTH =FILL_PARENT。)我在想什么?
In list.xml, the Listview has android:layout_width="fill_parent" so it should be the full width of the screen. (All of the items in row.xml are also width="fill_parent".) What am I missing?
推荐答案
在你的list.xml TextView的需要设置为FILL_PARENT。选择将后装配父的ListView的宽度。
The TextView in your list.xml needs to be set to fill_parent. The selection will then fit the width of the parent ListView.
android:layout_width="wrap_content"
这篇关于在ListView的宽度可点击区域的W / onListItemClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!