【问题标题】:Width of clickable area in ListView w/ onListItemClickListView 中可点击区域的宽度 w/ onListItemClick
【发布时间】:2013-02-12 22:55:16
【问题描述】:

我正在尝试将列表项放入可单击的 ListView 中。目前它们是可点击的(见我的截图),但它们只能在文本占据的矩形内点击。

我正在使用protected void onListItemClick(ListView l, View v, int position, long id) { 对于可点击的列表项。

这是我的 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>

还有here's the screenshot example: (新用户不能发图...抱怨...有超链接!)

在 list.xml 中,Listview 有 android:layout_width="fill_parent" 所以它应该是屏幕的全宽。 (row.xml 中的所有项目也是 width="fill_parent"。)我缺少什么?

【问题讨论】:

    标签: android listview


    【解决方案1】:

    list.xml 中的TextView 需要设置为fill_parent。然后选择将适合父 ListView 的宽度。

          android:layout_width="wrap_content"
    

    【讨论】:

    • 试过了,没用。该 TextView 仅在列表为空时使用。 ://
    • hmmm....啊,我的代码和你的代码中唯一的区别是LinearLayout也设置为layout_width上的fill_parent。试试看。如果这不起作用,我会打开我的代码并在此处发布。
    • 要清楚,我在上一条评论中指的是您 list.xml 中的 LinearLayout。它设置为 wrap_content。为我工作,将其更改为 fill_parent。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-16
    相关资源
    最近更新 更多