Android的 - GridLayout的单元尺寸 [英] Android - GridLayout cell sizes

查看:380
本文介绍了Android的 - GridLayout的单元尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用GridLayout的ImageViews。我的问题是,我有自己的设计都是不同的大小。我已经设置的行数和列数,但不知何故,我需要设置一个固定的单元尺寸(以某种方式统一 - 在单元格的宽度=总列/ NUM和行的单元格高度=总/ NUM)。我想这样做,这样,当我设置的高度和ImageView的到match_parent的宽度,图像视图不扩大超出了细胞的大小和布局看起来均匀。

I am trying to use GridLayout with ImageViews. My problem is that the images I have are all different sizes. I have set the row count and column count, but somehow I need to set a fixed cell size (somehow uniform - as in cell width = total / num of columns, and cell height = total / num of rows). I want to do this so that when I set height and width of imageview to match_parent, the image view doesn't expand beyond the cell size and the layout looks uniform.

我需要5行3列。有人建议如何做到这一点?

I need 5 rows and 3 columns. Can someone suggest how to do this ?

推荐答案

我回答过类似的问题<一href=\"http://stackoverflow.com/questions/23890588/long-text-on-button-messes-up-gridlayout-rows/23890689#23890689\">here.理论是使用包装布局为你的细胞,并提供它需要它的边缘。然后使用ImageView的这种布局中。因此,外布局充当您的ImageView的一个容器,它永远不会走出束缚其父的。

I answered a similar question here. The theory is to use a wrapper layout for your cell and provide the margins that it needs to it. Then use the imageview inside this layout. Thus the outer layout acts as a container for your imageview and it will never go out of the bound of its parent.

这篇关于Android的 - GridLayout的单元尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆