在我的应用程序中,我有2个线性布局:一个在顶部,一个在底部。固定比例的屏幕布局
我想那不管是在这些布局里面,顶层的布局占据了屏幕高度的60%和底层布局的40%。 这里是我的XML代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1.0" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.6"
android:orientation="vertical"
android:id="@+id/layout_top">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="0.4"
android:id="@+id/layout_bottom">
</LinearLayout>
</LinearLayout>
当这些布局都是空的,没有任何问题,他们有良好的比例。
问题是,如果我把一个小的列表视图的顶部布局为例如,那么布局将采用列表视图的大小,并不会保留60/40%的比例。
即使我的列表视图很小(例如只有3个项目),布局保留了60%,因此在我的列表视图下放置了一些空白空间。
我试过把android:layout_height
改成match_parent
但是它没有改变任何东西。
谢谢。
你的布局似乎很好。你能否展示你如何在顶层布局中添加一个小的列表视图。 – rizzz86