저는 ImageView
이며 layout_height
을 "100dp"로 설정하고 layout_width를 "wrap_content"로 설정했습니다.ImageView adjustViewBounds가 상대 레이아웃과 작동하지 않습니다.
사용 가능한 드로어 블은 130dp (너비) X 215dp (높이)보다 큰 실제 크기를 사용합니다. I adjustViewBounds
true로 설정하는 경우가 ImageView
하는 LinearLayout
내에 배치된다
, 상기 그리기의 종횡비와 layout_width에 따라 측정되는 폭을 얻는다.
그러나 RelativeLayout
안에 배치하면 ImageView
은 adjustViewBounds 설정에 관계없이 드로어 블 (130dp)과 동일한 너비를 갖습니다.
두 경우 모두 이미지가 왜곡없이 렌더링되지만 이미지 뷰의 경계는 다릅니다.
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>
있는 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>
왜 다르게 이러한 두 시나리오에서 ImageView
조치를합니까? ImageView
이 항상 LinearLayout 케이스에있는 것처럼 동작하도록 만드는 방법이 있습니까 (LinearLayout으로 배치하는 것이 효과적이지만 깨끗한 솔루션은 아닙니다).
match_parent한다. – Petrakeas
@Petrakeas 내가 대답을 업데이트, 내 애플 리케이션에서 그것을 시도, 잘 작동 –
'android : maxHeight' 트릭을 할 것 같다! 그러나 왜 그것이 필요합니까? LinearLayout 내부는 모두 예상대로 작동합니다. RelativeLayout의 동작이 정확합니까? – Petrakeas