我有两个图像视图:
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="visible"
android:src="@drawable/ic_logo"/>
<ImageView
android:id="@+id/logo_small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:visibility="invisible"
android:scaleType="centerCrop"
android:src="@drawable/ic_logo_small"/>
logo_small只是徽标的大小调整版本(宽度和高度已调整为75%)。我注意到logo.getGlobalVisibleRect(logoRect)返回不同宽高比的尺寸,与logo_small.getGlobalVisibleRect(logoSmallRect)相比。为什么会这样? 编辑: 根据要求,这里有更多代码:
final ImageView logo = (ImageView) findViewById(R.id.logo);
final ImageView logo_small = (ImageView) findViewById(R.id.logo_small);
Rect logoRect = new Rect();
Rect logoSmallRect = new Rect();
logo.getGlobalVisibleRect(logoRect);
logo_small.getGlobalVisibleRect(logoSmallRect);
Log.d("LOGO", "logo aspect ratio " + ((float)logoRect.width()/ logoRect.height()) + ", logo_small aspect ratio " + ((float)logoSmallRect.width()/ logoSmallRect.height()));
我得到的是:
D/LOGO﹕ logo aspect ratio 1.0682492, logo_small aspect ratio 1.2081686