ImageView的不拉伸以适应屏幕 [英] imageView is not stretching to fit the screen
问题描述
我有一个可绘制的,它需要为背景,以工作。它需要拉伸以填充屏幕(忽略宽高比)。
我已经提供了LDPI,MDPI,华电国际和xhdpi适当的大小。
(我知道他们是适当的由相应的宽度和高度的比例,是否足够呢?)
我试图做到这一点如下:
使用scaleType:fitXY上的ImageView 的
这不会留下白边围绕(内?)的ImageView的。
块引用>
一个解决,我很不满意,正在使用中心像这样scaleType:的
我不太满意,因为这个问题仍然在平板电脑屏幕存在。
的 注意:的
- 正如你可能已经注意到,我在其他地方尝试了建议的修复
在SO如设置调整视图边界为true。他们没有帮助
这里。 :(- 我想一个非程序化的回答/修复,如在XML本身这样做。我不会真的要被写code设置背景图片;寿命应当比简单得多。 (:P)
更新1:的
下面是XML布局
<合并的xmlns:机器人=http://schemas.android.com/apk/res/android> !< - <的FrameLayout的xmlns:机器人=http://schemas.android.com/apk/res/android - >
< - 的xmlns:工具=http://schemas.android.com/tools - >
< - 机器人:ID =@ + ID / FrameLayout1 - >
!< - 机器人:layout_width =FILL_PARENT - >
!< - 机器人:layout_height =FILL_PARENT - >
< - 工具:上下文=闪屏。> - >
<! -
这的FrameLayout镶石及其子基于使用系统的窗口
机器人:fitsSystemWindows
- > <查看
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
安卓的onClick =onClickTapToContinue
>
< /视图> < ImageView的
机器人:ID =@ + ID / bg_gradient
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:layout_gravity =补
机器人:adjustViewBounds =真
机器人:contentDescription =@字符串/ this_is_the_background_image
机器人:scaleType =中心
机器人:SRC =@绘制/ bg_gradient/> < ImageView的
机器人:ID =@ + ID / bg_artwork
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =中心
机器人:adjustViewBounds =真
机器人:contentDescription =@字符串/ artwork_man
机器人:SRC =@绘制/ bg_artwork/> <! - < /&的FrameLayout GT; - > < ImageView的
机器人:ID =@ + ID /品牌
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =中心|顶
机器人:adjustViewBounds =真
机器人:contentDescription =@字符串/ branding_text
安卓了maxHeight =95dp
机器人:paddingTop =5DP
机器人:SRC =@绘制/ title_wlcm/> <的TextView
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =底部|中心
机器人:paddingBottom会=5DP
机器人:文字=@字符串/ tap_continue
机器人:textAppearance =机器人:ATTR / textAppearanceSmall
机器人:文字颜色=@机器人:彩色/白/>< /合并>
解决方案该砍我一起去的作为是手机,也许为WVGA另一组图像(和布局?)(现在使用这组图片片)。
没有试过尚未虽然。我会用截图尽快张贴我
做的。
块引用>编辑:图它与图像本身的事情。有透明边框。会要求设计师进行修复。 :)
I have a drawable, which needs to work as the background. It needs to stretch to fill the screen (ignoring the aspect ratio).
I have provided appropriate sizes for ldpi,mdpi,hdpi and xhdpi. (I know they are appropriate by the ratio of the corresponding widths and heights, is that enough?)
I have tried to do this as follows:
using scaleType:fitXY on the imageView
This does leaves a white margin around (inside?) the imageView.
A work around that I'm not satisfied with is using centre for the scaleType like this:
I'm not satisfied because the problem still exists on tablet screens.
Note:
- As you might have noticed, I have tried the suggested fixes elsewhere on SO like setting Adjust View Boundaries to true. They didn't help here. :(
- I would like a non-programmatic answer/fix, as in doing this in XML itself. I wouldn't really want to be writing code to set a background image; Life should be much simpler than that. (:P)
Update 1:
Here's the XML Layout
<merge xmlns:android="http://schemas.android.com/apk/res/android" > <!-- <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" --> <!-- xmlns:tools="http://schemas.android.com/tools" --> <!-- android:id="@+id/FrameLayout1" --> <!-- android:layout_width="fill_parent" --> <!-- android:layout_height="fill_parent" --> <!-- tools:context=".SplashScreen" > --> <!-- This FrameLayout insets its children based on system windows using android:fitsSystemWindows --> <View android:layout_width="fill_parent" android:layout_height="fill_parent" android:onClick="onClickTapToContinue" > </View> <ImageView android:id="@+id/bg_gradient" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="fill" android:adjustViewBounds="true" android:contentDescription="@string/this_is_the_background_image" android:scaleType="center" android:src="@drawable/bg_gradient" /> <ImageView android:id="@+id/bg_artwork" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:adjustViewBounds="true" android:contentDescription="@string/artwork_man" android:src="@drawable/bg_artwork" /> <!-- </FrameLayout> --> <ImageView android:id="@+id/branding" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center|top" android:adjustViewBounds="true" android:contentDescription="@string/branding_text" android:maxHeight="95dp" android:paddingTop="5dp" android:src="@drawable/title_wlcm" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|center" android:paddingBottom="5dp" android:text="@string/tap_continue" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="@android:color/white" /> </merge>
解决方案The hack I'm going with for now is using these set of images as is for phones and maybe another set of images(and layouts?) for WVGA(Tablets).
Haven't tried this yet though. I'll post with screenshots as soon as I do.
Edit: Figures it had to do with the images themselves. There was transparent padding. Will ask designer to fix it. :)
这篇关于ImageView的不拉伸以适应屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!