我有一个可绘制的,它需要作为背景。它需要拉伸才能填满屏幕(忽略宽高比)。imageView没有拉伸到适合屏幕
我已经为ldpi,mdpi,hdpi和xhdpi提供了合适的大小。 (我知道它们适合通过相应的宽度和高度的比率,是足够?)
我试图做到这一点,如下所示:在ImageView的 fitXY:使用scaleType
这会在imageView的周围留下一个白色边缘。
一个解决,我很不满意使用中心scaleType这样的:
我不满意,因为这个问题仍然存在于平板电脑屏幕。
注:
- 正如你可能已经注意到,我在其他地方 尝试了建议的修复上这么喜欢设置调整视图边界为true。他们在这里没有帮助 。 :(
- 我想要一个非程序化的答案/修复,就像在XML本身做的那样,我不想真的想写代码来设置背景图片;生活应该比这更简单。 P)
更新1:
这里的XML布局
<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>
让我补充一点,我试过其他scaleType选项,而那些似乎并没有解决它。 (在所见即所得编辑器中看到) –
您可以尝试使用'layout_width'和'layout_height'等于''match_parent“''通过usig'android:background =”@ drawable/bg_gradient“'将背景添加到父LinearLayout本身。 – pyus13
@ pyus13我曾尝试过,但这确实没有帮助。我得到了类似的结果。 而我在这里使用framelayout的原因是:1)我可以“合并”并消除一个层次的视图层次结构2)梯度,人,品牌是所有不同的图像,需要重叠 –