如何在ListView中查看元素

问题描述 投票:0回答:2

据我所知,列表视图占据所有屏幕尺寸。

  1. 但是如何在屏幕底部为按钮留出空白?
  2. 还有如何查看列表下方的总和文本?

这里是片段的xml文件的一部分,没有底部导航。

  • 在相对布局中,我有一定数量的服务文本,项目列表和总计文本。
  • 相对布局后,我有带有2个按钮的线性布局
  • 这两个布局均为线性布局
       <RelativeLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_below="@+id/services_list_view"
        android:orientation="vertical"
        android:weightSum="100">

        <LinearLayout
            android:id="@+id/amount_of_positions"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Amount of services: "/>

            <TextView
                android:id="@+id/amount_of_services"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>

        </LinearLayout>

        <ListView
            android:id="@+id/services_list_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/amount_of_positions"
            android:layout_alignParentStart="true"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/services_list_view">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="50"
                android:text="Total Sum:" />

            <TextView
                android:id="@+id/total_price_for_all_services"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="50"
                android:text="0"
                android:textAlignment="textEnd" />

        </LinearLayout>

    </RelativeLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_gravity="bottom">

        <Button
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Confirm"/>

        <Button
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Cancel"/>

    </LinearLayout>

在图像上,我将新项目添加到列表中,并且在某些项目之后,我将按钮从屏幕上松开。

problem

android android-studio
2个回答
0
投票

在XML布局中,您将wrap_content用于ListView。如果使用wrap_content,则意味着ListView将继续增加其高度,直到适合所有子项为止。由于将其固定在ListView的底部,这将向下推底部视图。对于RecyclerViewListView,最佳做法是设置固定高度。您可以通过以下方式进行操作。


0
投票

ListView不一定占据整个屏幕高度。您可以尝试的方法:

© www.soinside.com 2019 - 2024. All rights reserved.