public class SquareImageView extends androidx.appcompat.widget.AppCompatImageView {
public SquareImageView(@NonNull Context context) {
super(context);
}
public SquareImageView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public SquareImageView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, widthMeasureSpec);
}
}
使用:
<com.x.x.recruitment.widget.SquareImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:background="@drawable/pic_qr_code" />