开发者

Relative stacking with Linear Layout in Android?

开发者 https://www.devze.com 2023-01-13 08:30 出处:网络
I have 6 images I want to display as 2 rows with 3 images in each. I\'m using nested LinearLayouts to achieve this, an开发者_C百科d it works well except for one thing:

I have 6 images I want to display as 2 rows with 3 images in each. I'm using nested LinearLayouts to achieve this, an开发者_C百科d it works well except for one thing:

The height of the largest image dictates the size of the linear layout, meaning there is empty space a lot of the time. In other words, my problem is as follows:

Relative stacking with Linear Layout in Android?

I keep getting the layout shown on the left, and I want the layout shown on the right.

I am aware that you can just use GridView, but that will still prevent the exact layout shown on the right, so I'm at a loss really. Many thanks.


Instead of 2 rows of three columns, you need 3 columns of 2 rows. LinearLayouts would be fine, just to be sure set the Gravity of the individual cells to Gravity.TOP.


You could equally achieve the whole grid using RelativeLayout instead of Linear. Each of your bottom row would just need android:layout_below and android:layout_alignLeft set to be the ImageView above it.

0

精彩评论

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