使 GridView 项变成正方形 [英] Making GridView items square
本文介绍了使 GridView 项变成正方形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望 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);
}
这篇关于使 GridView 项变成正方形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文