android - 带有 onListItemClick 的 ListView 中可点击区域的宽度

标签 android listview

我正在尝试让 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"。)我错过了什么?

最佳答案

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

      android:layout_width="wrap_content"

关于android - 带有 onListItemClick 的 ListView 中可点击区域的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6497000/

相关文章:

java - Android ThreadPoolExecutor 和 join()

jquery - 将文本添加到输入字段,而不是用 ListView + jQuery Mobile 替换它

java - "onRadioButtonClicked"方法不适用于由 "onCreate"方法实现的单选按钮

android - 为什么 getHandler() 返回 null?

javascript - React native 模块允许您复制/选择 View 中包含的文本

android - Android 上没有 WebView 的 oAuth?

android - android中listview每行item背景色的设置

Android SDK - 获取字符串值的 R.id (int)

javascript - 在 jQuery Mobile 中动态构建可折叠数据集的技术是什么

java - Listview 上的 setOnItemClickListener 扩展 Activity