2012-07-24 59 views
1

我需要在行中顯示3個按鈕,在列中顯示3個按鈕意味着總計9個按鈕,其中
屏幕。我將Horizo​​ntal:Layout_weight 0.33分配給水平LinearLayout中的每個。這是
與每個屏幕兼容,但我需要也垂直設置重量。如何垂直分配線性佈局中的重量?

總之我需要創建一個屏幕9按鈕,它應該與每個屏幕
屏幕兼容。我該如何做到這一點?如果是的話,我們可以垂直設定體重嗎?
在此先感謝...

回答

1

創建3個單獨的LinearLayouts,每行一個,並將它們封裝在垂直LinearLayout中。然後給3個LinearLayouts相同的重量。

僞:

<VerticalLinearLayout> 

    <HorizontalLinearLayout> 
     <Button 1 /> 
     <Button 2 /> 
     <Button 3 /> 
    </HorizontalLinearLayout> 

    <HorizontalLinearLayout> 
     <Button 4 /> 
     <Button 5 /> 
     <Button 6 /> 
    </HorizontalLinearLayout> 

    <HorizontalLinearLayout> 
     <Button 7 /> 
     <Button 8 /> 
     <Button 9 /> 
    </HorizontalLinearLayout> 

</VerticalLinearLayout> 

傾其所有的3的權重,除了VerticalLinearLayout。確保所有的layout_widths和layout_heights都設置爲fill_parent。

+0

也許你想看看這個答案:http://stackoverflow.com/a/4568183/191235 – Tom 2012-07-24 21:45:35

+0

謝謝!它的工作.....任何其他方式來設計與每個手機兼容的屏幕? – 2012-07-24 21:47:57

+0

@sandiparmal這應該適用於所有Android手機。 – 2012-07-24 21:51:47

0

可行源

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1"> 

     <Button 
      android:id="@+id/btnSales" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:text="Sales" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1"> 
     <Button 
      android:id="@+id/btnProduction" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:text="Production" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1"> 

     <Button 
      android:id="@+id/btnStock" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:text="Stock" /> 

    </LinearLayout> 
</LinearLayout>