2012-05-24 64 views
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会计算所有尺寸?

谢谢。

+0

你应该使用'Android的指定weight属性:layout_weight' – thepoosh

+0

给电网和框架布局相同的重量。 – Urban

+0

这是一个Java的问题...? – Bhavin

回答

6

您可以通过两个加layout_weight="1"如下

<?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> 
+3

+1 Good Answer ..... –

0

的FrameLayout & gridview的