使GridView项目成方形 [英] Making GridView items square

查看:99
本文介绍了使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屋!

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