我创建了一组嵌套LinearLayout
来组成按钮网格;设置组中每个组和每个孩子的重量,但是对齐方式不会正确。
拥有如此多的嵌套布局似乎并不正确...有更好的方法吗?
这是一个说明我的问题的图片:
代码很长,所以我只描述大纲:
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
关注@R9j's answer我已切换到RelativeLayout
并取得了一些进展。但是,ImageView
s重叠存在浮动问题。轻微的尺码问题;我需要很好地将所有内容都装入4.7“Nexus 4屏幕。
答案 0 :(得分: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。
答案 1 :(得分:0)