我有包含ImageView的和其他一些布局和视图垂直的LinearLayout。
< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =match_parent
机器人:layout_height =match_parent>
< ImageView的
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:contentDescription =@字符串/ banner_alt
机器人:SRC =@可绘制/ banner_portrait/>
<的TextView
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:文本=@字符串/ main_search
机器人:重力=中心
机器人:TEXTSTYLE =黑体/>
<的LinearLayout
机器人:方向=横向
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT>
<微调
机器人:ID =@ + ID / search_city_spinner
机器人:layout_width =0px
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:提示=@字符串/ search_city_prompt
机器人:项=@阵列/ search_city_array/>
<微调
机器人:ID =@ + ID / search_area_spinner
机器人:layout_width =0px
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:提示=@字符串/ search_area_prompt
机器人:项=@阵列/ search_area_array/>
< / LinearLayout中>
<的LinearLayout
机器人:方向=横向
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT>
<微调
机器人:ID =@ + ID / search_rooms_spinner
机器人:layout_width =0px
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:提示=@字符串/ search_rooms_prompt
机器人:项=@阵列/ search_rooms_array/>
<微调
机器人:ID =@ + ID / search_min_spinner
机器人:layout_width =0px
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:提示=@字符串/ search_min_prompt
机器人:项=@阵列/ search_min_array/>
<微调
机器人:ID =@ + ID / search_max_spinner
机器人:layout_width =0px
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:提示=@字符串/ search_max_prompt
机器人:项=@阵列/ search_max_array/>
< / LinearLayout中>
<按钮
机器人:ID =@ + ID / saearch_button
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:文本=@字符串/ search_button
机器人:的onClick =searchButton/>
< / LinearLayout中>
我的问题是在显示活动时,该ImageView的具有填充在顶部&安培;底部。我已经证实了它是ImageView的(通过设置在ImageView的背景色)。
图片为450x450px。手动设置的高度450px产生所需的效果(没有填充),并把它置450dp产生相同的效果使用WRAP_CONTENT
似乎机器人走的是图像的高度(450px),而将该ImageView的为相同的值的高度,但在DP
任何想法,我能做些什么来解决这个问题?我不想用绝对值,因为我会提供不同的图像,不同的屏幕密度。
解决方案我有一个simular问题并解决它使用机器人:adjustViewBounds =真正的
在ImageView的。
< ImageView的
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:adjustViewBounds =真
机器人:contentDescription =@字符串/ banner_alt
机器人:SRC =@可绘制/ banner_portrait/>
I have a vertical LinearLayout containing an ImageView and a few other layouts and views.
<?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>
My problem is that when the activity is displayed, the ImageView has a padding at the top & bottom. I've confirmed it is the ImageView (by setting a background colour on the ImageView).
The image is 450x450px. Setting the height manually to 450px produces the desired effect (no padding), and setting it to 450dp produces the same effect as using wrap_content.
It seems that android is taking the height of the image (450px) and setting the height of the ImageView to the same value, but in dp.
Any ideas as to what I can do to fix this? I don't want to use absolute values as I'll be providing different images for different screen densities.
解决方案I had a simular issue and resolved it using android:adjustViewBounds="true"
on the ImageView.
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@string/banner_alt"
android:src="@drawable/banner_portrait" />
上一篇:ICU编译Android的 - “uint64_t中”没有指定类型类型、ICU、Android、uint64_t
下一篇:在Eclipse或Android Studio的XML编辑器没有行号行号、编辑器、Android、Eclipse