感觉hencoder有点烂尾了呀,课程地址
http://hencoder.com/ui-2-1/
http://hencoder.com/ui-2-2/
http://hencoder.com/ui-2-3/
上代码
@SuppressLint("AppCompatCustomView")
public class Sample01SquareImageView extends ImageView {
public Sample01SquareImageView(Context context) {
super(context);
}
public Sample01SquareImageView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public Sample01SquareImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int measuredWidth = getMeasuredWidth();
int measuredHeight = getMeasuredHeight();
if (measuredWidth > measuredHeight) {
measuredWidth = measuredHeight;
} else {
measuredHeight = measuredWidth;
}
setMeasuredDimension(measuredWidth, measuredHeight);
}
}