2010-10-27 72 views
1

我是新的Android平臺。我試圖製作一個視圖,將屏幕分爲三部分。第一部分應該是200dip高,第三部分應該是50高,中間部分應該留在中間的剩餘部分。有什麼辦法可以實現它嗎?我嘗試了一些方法,但是它不起作用或應用程序崩潰。 感謝您的幫助 Patrik動態視圖高

回答

1

當然。使用一個看起來像這樣的RelativeLayout。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <!-- Defining the top view --> 
    <View android:layout_alignParentTop="true" 
    android:layout_height="200dip" 
    android:layout_width="fill_parent" 
    android:id="@+id/top_view" 
    android:background="#FFFF00"/> 
    <!-- Defining the bottom view --> 
    <View android:layout_alignParentBottom="true" 
    android:layout_height="50dip" 
    android:layout_width="fill_parent" 
    android:id="@+id/bottom_view" 
    android:background="#00FFFF"/> 
    <!-- Defining the view in between those views --> 
    <View android:layout_above="@id/bottom_view" 
    android:layout_below="@id/top_view" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#FF0000"/> 
</RelativeLayout> 

在代碼中爲您提供了註釋。

+0

我喜歡這個建議甚至比我的更好。 +1 – Ralkie 2010-10-27 09:44:01

0

我通常通過設置固定視圖爲特定值(例如android:layout_height="200dp")layout_height /寬度,並用爲android:layout_height="wrap_content"動態查看設置android:layout_weight="1"實現這一點。在這種情況下,LinearLayout應該被用作包含ViewGroup。