Android 如何使我的ListView项目始终按内容高度包装

Android 如何使我的ListView项目始终按内容高度包装,android,Android,现在,如果列表项的高度为2行,则所有行的高度均为2行 如何使行的高度独立于其他行 列表视图 划船 行xml文件的容器是否也设置为包装内容?是否使用自定义适配器?您发布的XML应该可以快速浏览,但是您可能会错误地膨胀视图,从而忽略wrap_content属性。如果您使用的是自定义适配器,请发布其代码,否则只需发布用于显示列表的Java代码即可。 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

现在,如果列表项的高度为2行,则所有行的高度均为2行

如何使行的高度独立于其他行

列表视图

划船


行xml文件的容器是否也设置为包装内容?是否使用自定义适配器?您发布的XML应该可以快速浏览,但是您可能会错误地膨胀视图,从而忽略wrap_content属性。如果您使用的是自定义适配器,请发布其代码,否则只需发布用于显示列表的Java代码即可。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/user_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:divider="@null" />

</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:paddingBottom="1dp"
    android:paddingTop="1dp"
    android:paddingLeft="8dp"
    android:paddingRight="8dp" >

    <TextView
        android:id="@+id/user_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:maxLines="2"
        android:ellipsize="middle"
        android:textColor="@android:color/holo_blue_dark"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/points"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:layout_weight="1"
        android:gravity="right"
        android:textStyle="bold" />

</LinearLayout>