据我所知,列表视图占据所有屏幕尺寸。
这里是片段的xml文件的一部分,没有底部导航。
<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>
在图像上,我将新项目添加到列表中,并且在某些项目之后,我将按钮从屏幕上松开。
在XML布局中,您将wrap_content
用于ListView
。如果使用wrap_content
,则意味着ListView将继续增加其高度,直到适合所有子项为止。由于将其固定在ListView的底部,这将向下推底部视图。对于RecyclerView
或ListView
,最佳做法是设置固定高度。您可以通过以下方式进行操作。
ListView不一定占据整个屏幕高度。您可以尝试的方法: