0

我正在尝试在 xml 中完成以显示半框架布局和半网格布局,而无需自己指定dp 这是我想要的:

<?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" >

    <FrameLayout
        android:id="@+id/top"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:background="#FFFF00"
        android:layout_weight="0"
        android:orientation="vertical" >

    </FrameLayout>

    <GridView
        android:id="@+id/buttom"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:numColumns="3" >
    </GridView>

</LinearLayout>

我不想指定这个的大小:

android:layout_height="250dp"

因为我需要为所有尺寸重新创建这个 xml。也许我可以改变一些东西,android会计算所有尺寸?

谢谢。

4

2 回答 2

6

您可以按如下方式指定重量属性

<?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" >

    <FrameLayout
        android:id="@+id/top"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="#FFFF00"
        android:layout_weight="1" >

    </FrameLayout>

    <GridView
        android:id="@+id/buttom"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:numColumns="3" 
        android:layout_weight="1">
    </GridView>

</LinearLayout>
于 2012-05-24T07:18:36.570 回答
0

通过添加layout_weight="1"框架布局和网格视图

于 2012-05-24T07:21:23.100 回答