2013-01-04 95 views
5

我有一个可绘制的,它需要作为背景。它需要拉伸才能填满屏幕(忽略宽高比)。imageView没有拉伸到适合屏幕

我已经为ldpi,mdpi,hdpi和xhdpi提供了合适的大小。 (我知道它们适合通过相应的宽度和高度的比率,是足够?)

我试图做到这一点,如下所示:在ImageView的 fitXY:使用scaleType

这会在imageView的周围留下一个白色边缘。

fitXY image

一个解决,我很不满意使用中心scaleType这样的:

我不满意,因为这个问题仍然存在于平板电脑屏幕。 enter image description here

注:

  • 正如你可能已经注意到,我在其他地方 尝试了建议的修复上这么喜欢设置调整视图边界为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> 
+0

让我补充一点,我试过其他scaleType选项,而那些似乎并没有解决它。 (在所见即所得编辑器中看到) –

+0

您可以尝试使用'layout_width'和'layout_height'等于''match_parent“''通过usig'android:background =”@ drawable/bg_gradient“'将背景添加到父LinearLayout本身。 – pyus13

+0

@ pyus13我曾尝试过,但这确实没有帮助。我得到了类似的结果。 而我在这里使用framelayout的原因是:1)我可以“合并”并消除一个层次的视图层次结构2)梯度,人,品牌是所有不同的图像,需要重叠 –

回答

1

我会用现在使用这些设置图像的黑客s适用于手机,也可能是WVGA(平板电脑)的另一组图像(和布局?)。

虽然还没有尝试过。只要我 做了,我会尽快发布截图。

编辑:数字它必须做的图像本身。有透明的填充。请问设计师来解决它。 :)

0

在eclipse中活动的图形布局中,您可以右键单击该活动,然后选择“编辑背景”。这将允许您将图片设置为覆盖屏幕所有边缘的背景。 希望这可以帮助,欢呼吉姆

+0

谢谢你的回答。但是,它不只是设置这个图像的背景的src?如果有的话,仍然显示图像的缺陷。 (发布在我的答案中,我应该将该部分移至Q)吗? –

1

而不是使用android:src =“...”,使用android:background =“...”属性。希望它有效。