xml中为wrap_content,为什么会在 switch (widthMode)中出现两种情况?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ddd.customview1.SimpleView2
android:layout_centerInParent="true"
android:id="@+id/progress"
app:progress="0"
app:bgcolor="@color/colorAccent"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
Log.v("haha--","00000000000");
switch (widthMode) {
case MeasureSpec.EXACTLY:
mWidth = 200;
mHeight = 30;
Log.v("haha--","2222222222");
break;
case MeasureSpec.AT_MOST:
mWidth = 400;
mHeight = 30;
Log.v("haha--","11111111111111");
break;
case MeasureSpec.UNSPECIFIED:
break;
}
setMeasuredDimension(mWidth,mHeight);
}
运行结果是: 11111111111111 之后 又打印了2222222
wrap_content不是只对应着 case MeasureSpec.AT_MOST: 这种情况吗?