[英]GridView Stretch Row Height?
I am using GridView in my application. 我在我的应用程序中使用GridView。 And i am wondering if there is an equivalent to GridView.STRETCH_COLUMN_WIDTH , for row heights.
我想知道是否有等效于GridView.STRETCH_COLUMN_WIDTH的行高。
In other words, i want the height of the images in the GridView cells, to be stretched, like their width is. 换句话说,我希望GridView单元格中图像的高度像其宽度一样被拉伸。
Is there an easy way? 有没有简单的方法? Or I would have to fix it through the image adapter ?
还是我必须通过图像适配器修复它?
Thanks in advance. 提前致谢。
You can create an image view whose width changes according to height. 您可以创建一个图像视图,其宽度根据高度而变化。 This way if the
GridView
only has an ImageView
, it will stay squared. 这样,如果
GridView
仅具有ImageView
,它将保持平方。
For example: 例如:
public class SquareImageView extends ImageView {
public SquareImageView(final Context context) {
super(context);
}
public SquareImageView(final Context context, final AttributeSet attrs) {
super(context, attrs);
}
public SquareImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec)
{
int width = getDefaultSize(getSuggestedMinimumWidth(),widthMeasureSpec);
setMeasuredDimension(width, width);
}
@Override
protected void onSizeChanged(final int w, final int h, final int oldw, final int oldh)
{
super.onSizeChanged(w, w, oldw, oldh);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.