Pet*_*eas 8 android android-layout android-imageview android-relativelayout
我有一个ImageView
并设置layout_height
为"100dp",其layout_width设置为"wrap_content".
使用的可绘制的实际尺寸更大,为130dp(宽度)×215dp(高度).
当ImageView
放置在a中时LinearLayout
,如果我设置adjustViewBounds
为true,它将获得根据drawable的纵横比和layout_width测量的宽度.
然而,放置在内部时RelativeLayout
的ImageView
得到相同的宽度可提拉(130dp),不管adjustViewBounds设置.
在这两种情况下,图像都会呈现相关性而不会失真,但ImageView的界限是不同的.
RelativeLayout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light">
<ImageView
android:layout_width="wrap_content"
android:layout_height="100dp"
android:adjustViewBounds="true"
android:src="@drawable/phone_orange"
android:contentDescription="@null" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="100dp"
android:adjustViewBounds="true"
android:contentDescription="@null"
android:src="@drawable/phone_orange" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
为什么ImageView
这两种情况下的措施不同?有没有办法使ImageView
行为始终像在LinearLayout情况下(用LinearLayout包装它工作,但它不是一个干净的解决方案)?
Kir*_*nov 14
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxHeight="100dp"
android:adjustViewBounds="true"
Run Code Online (Sandbox Code Playgroud)