zoukankan      html  css  js  c++  java
  • Android-正方形的容器

    package liu.myrecyleviewchoosephoto.view;
    
    
    import android.content.Context;
    import android.util.AttributeSet;
    import android.widget.RelativeLayout;
    
    /**
     * 正方形的RelativeLayout
     * Created by 刘楠 on 2016/8/13 0013.16:07
     */
    public class SquareRelativeLayout extends RelativeLayout {
        public SquareRelativeLayout(Context context) {
            super(context);
        }
    
        public SquareRelativeLayout(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public SquareRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
        }
    
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    
    
            //设置自己测量结果
            setMeasuredDimension(getDefaultSize(0,widthMeasureSpec),getDefaultSize(0,heightMeasureSpec));
    
    
            /**
             * 测量子View的
             */
            int childWidthSize=getMeasuredWidth();
            //高度与宽度一样
            widthMeasureSpec =MeasureSpec.makeMeasureSpec(childWidthSize,MeasureSpec.EXACTLY);
            heightMeasureSpec =widthMeasureSpec;
    
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }
  • 相关阅读:
    MySQL关键性能监控(QPS/TPS)
    Python小技巧
    Redis高可用演进(一)
    防范XSS攻击
    java引用知识
    ehcache同步原理
    ehcache监控
    SecureCRT使用技巧
    JUC整理笔记五之梳理Varhandle(下)
    JUC整理笔记四之梳理VarHandle(上)
  • 原文地址:https://www.cnblogs.com/liunanjava/p/5768656.html
Copyright © 2011-2022 走看看