开发者

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

开发者 https://www.devze.com 2023-02-14 05:55 出处:网络
I need to lay out a centered row of 3 buttons above a centered row of 4 buttons: +------++------++------+

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

精彩评论

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