ImageView와 몇 가지 다른 레이아웃과 뷰를 포함하는 수직 LinearLayout을 가지고 있습니다.안드로이드 XML 레이아웃의 layout_height = "wrap_content"는 패딩 상한과 하한을 가짐
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/banner_alt"
android:src="@drawable/banner_portrait" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/main_search"
android:gravity="center"
android:textStyle="bold" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Spinner
android:id="@+id/search_city_spinner"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:prompt="@string/search_city_prompt"
android:entries="@array/search_city_array" />
<Spinner
android:id="@+id/search_area_spinner"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:prompt="@string/search_area_prompt"
android:entries="@array/search_area_array" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Spinner
android:id="@+id/search_rooms_spinner"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:prompt="@string/search_rooms_prompt"
android:entries="@array/search_rooms_array" />
<Spinner
android:id="@+id/search_min_spinner"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:prompt="@string/search_min_prompt"
android:entries="@array/search_min_array" />
<Spinner
android:id="@+id/search_max_spinner"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:prompt="@string/search_max_prompt"
android:entries="@array/search_max_array" />
</LinearLayout>
<Button
android:id="@+id/saearch_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/search_button"
android:onClick="searchButton" />
</LinearLayout>
내 문제는 활동이 표시 될 때 이미지 뷰 상단 & 하단에 패딩을 가지고 있다는 것입니다. ImageView에 배경색을 설정하여 ImageView라는 것을 확인했습니다.
이미지는 450x450 픽셀입니다. 높이를 수동으로 450px로 설정하면 원하는 효과 (패딩 없음)가 만들어지고 450dp로 설정하면 wrap_content를 사용할 때와 동일한 효과가 나타납니다.
안드로이드가 이미지 높이 (450px)를 취하고 ImageView의 높이를 같은 값으로 설정하고 있지만 dp로 보입니다.
이 문제를 해결하기 위해 내가 할 수있는 아이디어가 있습니까? 나는 다른 화면 밀도에 대해 서로 다른 이미지를 제공 할 것이므로 절대 값을 사용하고 싶지 않습니다.
이것은 나를위한 트릭입니다. 이것은 기본 설정이 아니라는 직관에 어긋나는 것처럼 보입니다. 그것은 "wrap_content"입니다. 그러나 실제로는 ... – erlando
저를 위해 일하지 않았습니다. 나는 이미지의 레이아웃이 바뀔 때마다 올바른 가로 세로 비율에 맞게 이미지의 크기를 수동으로 조절하기 위해 리스너를 추가했다. – gsteinert
그게 내 하루를 만든거야 :-) –