在相对的措施如何指定宽度的Andr​​oid网格布局细胞的高度? [英] How do I specify width and height of Android GridLayout cells in relative measures?

查看:93
本文介绍了在相对的措施如何指定宽度的Andr​​oid网格布局细胞的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出如何<一个href="http://android-developers.blogspot.no/2011/11/new-layout-widgets-space-and-gridlayout.html">GridLayout工作原理,但有一件事我不能从文档弄清楚是怎么或者一个可以控制网格单元的大小。

I'm trying to figure out how GridLayout works, but one thing I can't figure out from the documentation is how or if one can control the size of the grid cells.

说我要两两格,每个单元占据的屏幕房地产的整整25%(半高,半宽) - 我能做到这一点?

Say I want a two by two grid where each cell occupy exactly 25% of the screen real estate (half height, half width) - can I do this?

使用的LinearLayout我会通过嵌套两个水平​​的LinearLayout在一个垂直,然后分配为1 体重以所有元素做到这一点。网格布局不支持权重属性,但。

With LinearLayout I would accomplish this by nesting two horizontal LinearLayout's in one vertical and then assigning a weight of 1 to all elements. GridLayout does not support the weight property though.

推荐答案

它看起来像其设置为你想应该根据文档是相当简单:

it looks like setting it as you'd like should be fairly straightforward according to the documentation:

android:rowCount='2'
android:columnCount='2'

和中设置的儿童

android:layout_columnSpan="1"
android:layout_rowSpan="1"

基准也提到拉伸:

要prevent从绵延一列,确保列中的组成部分之一不定义重力。

To prevent a column from stretching, ensure that one of the components in the column does not define a gravity.

哪个似乎是一个解决方案,以保持在50:50比率的行和列不调整根据内容

Which would seem like a solution to keep the rows and columns in a 50:50 ratio without resizing according to content

这篇关于在相对的措施如何指定宽度的Andr​​oid网格布局细胞的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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