zoukankan      html  css  js  c++  java
  • Gridview 显示成正方形

    import android.content.Context;
    import android.util.AttributeSet;
    import android.widget.RelativeLayout;

    public class SquareLayout extends RelativeLayout{
    public SquareLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    }
    public SquareLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    }

    public SquareLayout(Context context) {
    super(context);
    }
    @SuppressWarnings("unused")
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // For simple implementation, or internal size is always 0.
    // We depend on the container to specify the layout size of
    // our view. We can't really know what it is since we will be
    // adding and removing different arbitrary views and do not
    // want the layout to change as this happens.
    setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec));

    // Children are just made to fill our space.
    int childWidthSize = getMeasuredWidth();
    int childHeightSize = getMeasuredHeight();
    //高度和宽度一样
    heightMeasureSpec = widthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY);
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
    }

  • 相关阅读:
    LeetCode
    LeetCode
    LeetCode OJ
    LeetCode OJ
    LeetCode OJ
    关于if和else和switch case的用法和程序编码操作过程
    关于java的特点
    关于JAVA的数据类型
    关于java的学习
    力扣482. 密钥字符串 S python--每天一题
  • 原文地址:https://www.cnblogs.com/nan325/p/SquareLayout.html
Copyright © 2011-2022 走看看