开发者

How to lay out 3 buttons above 4 buttons, centered?

I need to lay out a centered row of 3 buttons above a centered row of 4 buttons:

          +------+    +------+    +------+
          |      |    |      |    |      |
          +------+    +------+    +------+

    +------+    +------+    +------+    +------+
    |      |    |      |    |      |    |      |
    +------+    +------+ 开发者_如何学C   +------+    +------+

All the buttons are the same size and the inter-button gaps should be the same on both rows. I can do this easily with nested LinearLayouts, but I'd like to do this without nesting layout views. (Aside from all the advice to avoid nested layouts, I need to traverse the buttons in code and it's a lot easier with a flat layout.)

I can do this with a RelativeLayout if the rows have the same number of buttons, but I can't figure it out when the button counts differ. Is there a way to use one of the stock layout views (it seems silly to write a custom layout view for this) to do a flat layout?


It seems like this can't be done in single layout. You can't use relative layout because it doesn't support gravity and you need views center aligned.

Custom layout is a perfect solution for this case. It's not that hard really. I experienced a lot simpler cases that couldn't be done using single standard layout.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜