2012-06-15 27 views
0

我想弄清楚如何讓我的佈局有以下編碼按鈕留在他們的位置,儘管未來的動態活動,也許通過預留一個免費的空間。在菜單按鈕和其他三個按鈕之間,將會有一個按鈕的網格,其中包含隨機大小和隨機數量的按鈕,基於動態創建的預選。但是無論我想要在main.xml中設計的這四個按鈕保持在適當的位置上多少個按鈕或大小。如何爲將來的動態活動留出區域?

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

    <Button 
     android:id="@+id/menu" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="MENU" /> 

這是關注的領域。我想讓它位於屏幕上方的菜單按鈕(上圖)始終連接到屏幕的最下方,並且步驟,暫停和模擬按鈕(如下)始終位於屏幕的最底部。

<Button 
     android:id="@+id/step" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/grid" 
     android:layout_centerHorizontal="true" 
     android:text="STEP" /> 

    <Button 
     android:id="@+id/pause" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/grid" 
     android:layout_toLeftOf="@id/step" 
     android:text="PAUSE" /> 

    <Button 
     android:id="@+id/sim" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/grid" 
     android:layout_toRightOf="@id/step" 
     android:text="SIMULATE" /> 

    <SeekBar 
     android:id="@+id/speed" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/sim" 
     android:layout_alignParentLeft="true"/> 

</RelativeLayout> 

我剛想出一個解決方案我自己的問題。 我不得不在其他三個按鈕上使用「android:layout_alignParentBottom =」true「,現在任何動態添加的按鈕都可以根據需要放置在其間。

+0

每當你使用「Android動態佈局」這個詞時,你需要看看Java代碼,相比之下,XML非常僵硬和靜態。 – gobernador

回答

1

使您的RelativeLayout爲LinearLayout。給所有按鈕「android:layout_weight =」0「」然後在所需的空白處添加一個具有android:layout_height =「0」和「android:layout_weight =」1的View如果我正確理解你的問題,那就應該這樣做吧。