2011-12-19 65 views
0

我的應用程序的佈局設置爲480dpi寬,480/4是120.所以,如果我在應用程序頂部有4個按鈕,並且我將其設置爲120dpi寬,爲什麼按鈕佔用一半屏幕?!我怎樣才能讓按鈕在頂部平均分配尺寸?活動元素的寬度不正確?

在這裏,我只是增加了4個按鍵在頂部:

那麼前兩個按鈕是120 dpi的寬:

+0

發表您的佈局xml文件代碼.. – user370305 2011-12-19 05:28:58

回答

2

檢查了這一點:

<LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
     <Button 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 
     </Button> 
     <Button 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 
     </Button> 
     <Button 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 
     </Button> 
     <Button 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 
     </Button> 
    </LinearLayout> 
+0

嗯。那沒有做任何事情。我仍然看不到按鈕 – Cole 2011-12-19 05:42:38

+0

發佈您的代碼。 – josephus 2011-12-19 05:44:34

+0

好吧,它的工作。我必須在我的其他LinearLayout中添加該LinearLayout。謝謝您的幫助! – Cole 2011-12-19 05:51:30

1

可以使用FILL_PARENT參數進行佈局寬度併爲每個按鈕添加一個權重1以獲得期望的效果

+0

謝謝回答得這麼快。所以每個按鈕的寬度是「FILL_PARENT」,Activity的LinearLayout仍然是「match_parent」?你是什​​麼意思「添加一個重量1」的按鈕?當我這樣做,它說我需要提供一個layout_width屬性,我看不到按鈕。 – Cole 2011-12-19 05:36:08

0

試試這個

<TableRow android:layout_width="fill_parent" 
    android:weightSum="100" android:layout_height="wrap_content"> 
    <Button android:text="Button" android:layout_weight="25" 
     android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
    <Button android:text="Button" android:layout_width="wrap_content" 
     android:layout_weight="25" android:layout_height="wrap_content"></Button> 
    <Button android:text="Button" android:layout_weight="25" 
     android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
    <Button android:text="Button" android:layout_weight="25" 
     android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
</TableRow> 
相關問題