版权声明
- 本文原创作者:谷哥的小弟
- 作者博客地址:http://blog.csdn.net/lfdfhl
SquareImageView概述
SquareImageView为正方形的ImageView。
SquareImageView截图SquareImageView截图如下:
SquareImageView源码如下:
import android.content.Context;
import android.util.AttributeSet;
import androidx.appcompat.widget.AppCompatImageView;
public final class SquareImageView extends AppCompatImageView {
public SquareImageView(Context context) {
this(context, null);
}
public SquareImageView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public SquareImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY ? MeasureSpec.getSize(widthMeasureSpec) : 0;
int height = MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.EXACTLY ? MeasureSpec.getSize(heightMeasureSpec) : 0;
int spec = Math.max(width, height);
setMeasuredDimension(spec, spec);
}
}



