制作网格视图项方 [英] making grid view items square
本文介绍了制作网格视图项方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想我的GridView的项目是正方形。有2列和项目的宽度是'FILL_PARENT(例如,他们采取尽可能多的水平空间成为可能。该项目是自定义视图。
I would like the items of my GridView to be square. There are 2 columns and the items width is 'fill_parent' (e.g. they take as much horizontal space as possible. The items are custom views.
如何让我的项目高度等于其可变宽度?
How do I make the items height to be equal to their variable width?
推荐答案
目前在GridView的列被拉长一个简单的解决方案。刚刚覆盖的GridView的项目布局......在onMeasure
There is a simpler solution when GridView columns are stretched. Just override the onMeasure of the GridView item layout with...
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, widthMeasureSpec);
}
这篇关于制作网格视图项方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文