private void resetIconSize(final MarginLayoutParams params) {
        if (isInEditMode() || null == params) return;
        // 大分辨率的手机无须计算
        //if (getContext().getResources().getDisplayMetrics().densityDpi > 320) return;

        post(new Runnable() {
            @Override
            public void run() {
                int size = (int) getTextSize();
                int height = getMeasuredHeight();
                int diff = height > size ? height - size : 0;
                params.width = size;
                int add = (diff / 2) + (diff % 2);
                int dft = 10;
                params.height = size + (diff > dft ? add : 0);
                if (diff > dft) {
                    params.topMargin = -add;
                }
                setLayoutParams(params);
                invalidate();
            }
        });
    }
private void resetIconSize ( final MarginLayoutParams params ) { if ( isInEditMode ( ) || null == params ) return ; post ( new Runnable ( ) { @ Override public void run ( ) { int size = ( int ) getTextSize ( ) ; int height = getMeasuredHeight ( ) ; int diff = height > size ? height - size : 0 ; params . width = size ; int add = ( diff / 2 ) + ( diff % 2 ) ; int dft = 10 ; params . height = size + ( diff > dft ? add : 0 ) ; if ( diff > dft ) { params . topMargin = - add ; } setLayoutParams ( params ) ; invalidate ( ) ; } } ) ; }
根据LayoutParams手动重置宽高