2013-06-13 149 views
0

我創建了一組嵌套的LinearLayout s以形成按鈕網格;設置組中每個組和每個孩子的體重,但是對齊不會正確。Android XML佈局對齊(按鈕網格)

看起來好像沒有這麼多的嵌套佈局......有沒有更好的方法來做到這一點?

這是說明我的問題的圖像: android xml layout problem

的代碼是很長,所以我只能形容概要:

MAIN LINEAR LAYOUT (horizontal) 
    Col 1: linear layout (vertical) 
      contains two horizontal linear layouts with two buttons each (2x2 grid) 
    Col 2: linear layout (vertical) 
      contains three horizontal linear layouts with three buttons each (3x3 grid) 
    Col 3: linear layout (vertical) 
      contains two horizontal linear layouts with two buttons each (2x2 grid) 
END MAIN LINEAR LAYOUT 

按照要求here is the XML code

@R9j's answer我已經切換到RelativeLayout並取得了一些進展。但是,有一個浮動問題,其中ImageView重疊。也有輕微的尺寸問題;我需要適應一切都變成了4.7" 的Nexus 4屏幕很好過。

Progress with RelativeLayout

+0

你可以發佈你的XML嗎? – R9J

+0

@ R9j在我的文章中添加了一個指向XML的鏈接 – Ozzy

+0

您用於播放器控件(箭頭)的圖像似乎有很大的填充。你確定圖像沒有額外的填充?這些圖像中的每一個應該是一個正方形,它們的尺寸應該相等 – gunar

回答

1

這將有助於你

linearlayout (horizontal){ 
    relative layout(weight = 1){ 
     image view(alignParentTop=true, alignParentLeft=true) 
     image view(alignParentTop=true, alignParentRight=true) 
     image view(alignParentBottom=true, alignParentLeft=true) 
     image view(alignParentBottom=true, alignParentRight=true) 
    } 
    relative layout(weight = 1){ 
     image view(alignParentLeft=true, height=fillParent) 
     image view(alignParentRight=true, height=fillParent) 
     image view(alignParentTop=true, centerHorizontal=true) 
     image view(alignParentBottom=true, centerHorizontal=true) 
    } 
    relative layout(weight = 1){ 
     image view(alignParentTop=true, alignParentLeft=true) 
     image view(alignParentTop=true, alignParentRight=true) 
     image view(alignParentBottom=true, alignParentLeft=true) 
     image view(alignParentBottom=true, alignParentRight=true) 
    } 
} 

根據上述模型設計你的xml。

+0

會給它一個去,謝謝 – Ozzy

+0

歡迎您 – R9J

+0

它是好多了,但只有所有按鈕重疊的問題。我怎樣才能讓他們僵化? – Ozzy

0

你可以嘗試GridLayout

它也像你能做到這一點的RelativeLayout爲好,只是要一個更加仔細

編輯:發表您的XML文件,如果你有麻煩,如果我有時間,我會重做和發佈解決方案XML

+0

我正在研究GridLayout,並且在我的帖子中添加了XML的鏈接 – Ozzy

+0

GridLayout可用於API級別14 – gunar

+0

@gunar沒有問題,我只爲API 14-17設計 – Ozzy