【问题标题】:How to set ListView Height to auto?如何将 ListView 高度设置为自动?
【发布时间】:2015-09-24 23:25:03
【问题描述】:

我想将 ListView 的高度设置为 auto,这意味着我的项目将添加到 listview,然后高度也会自动增加。

<ScrollView
    android:id="@+id/abcd_scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerHorizontal="true" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <RelativeLayout
            android:id="@+id/profile_layout"
            android:layout_width="match_parent"
            android:layout_height="220dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:background="@drawable/blur_default_img">

            <RelativeLayout 
                android:id="@+id/profile_img_rt"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_marginTop="20dp"
                android:layout_marginLeft="20dp"
                android:gravity="center"
                android:background="@drawable/circle_white_bg">

        <com.example.RoundedImageView.RoundedImageView
            android:id="@+id/profile_img"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:src="@drawable/person_avatar" />

         </RelativeLayout>
       </RelativeLayout>
        <ListView 
           android:id="@+id/tab_pending_list"
           android:layout_width="fill_parent"
           android:layout_weight="1"
           android:layout_height="0dp"
           android:layout_below="@+id/profile_layout">
        </ListView>

  </LinearLayout>
</ScrollView>

所以这个 xml 请仔细阅读它并建议我解决如何自动增加列表视图高度的解决方案。

【问题讨论】:

  • 是的,我知道,但我已经更新了我的帖子,请仔细阅读。

标签: android listview height


【解决方案1】:

ListView 是一个可滚动的视图,因此您不应将它放在另一个可滚动的视图中,例如 ScrollView

ListView 将仅显示其后面的适配器描述的行。所以你需要做的就是删除ScrollView并保留ListViewandroid:height=wrap_content

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-15
    • 2015-03-16
    • 2011-09-07
    • 1970-01-01
    • 2017-11-27
    • 1970-01-01
    • 2013-10-07
    • 1970-01-01
    相关资源
    最近更新 更多