![](/img/trans.png)
[英]RelativeLayout Imageview android:layout_height=“wrap_content” not woking
[英]ImageView in android XML layout with layout_height="wrap_content" has padding top & bottom
我有一個包含 ImageView 和其他一些布局和視圖的垂直 LinearLayout。
<?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(通過在 ImageView 上設置背景顏色)。
圖像為 450x450 像素。 手動將高度設置為 450px 會產生所需的效果(無填充),將其設置為 450dp 會產生與使用 wrap_content 相同的效果。
似乎android正在獲取圖像的高度(450px)並將ImageView的高度設置為相同的值,但在dp中。
關於我可以做些什么來解決這個問題的任何想法? 我不想使用絕對值,因為我將為不同的屏幕密度提供不同的圖像。
我有一個類似的問題,並在 ImageView 上使用android:adjustViewBounds="true"
解決了它。
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@string/banner_alt"
android:src="@drawable/banner_portrait" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.