imageView无法拉伸以适应屏幕大小。

5
我有一个drawable需要作为背景。它需要拉伸以填满屏幕(忽略纵横比)。
我已经为ldpi、mdpi、hdpi和xhdpi提供了适当的大小。(我知道它们是适当的,因为相应宽度和高度的比率是正确的。)
我尝试过以下方法:在imageView上使用scaleType:fitXY。但这会在imageView周围留下白色边缘(内部?)。
一种解决方法是使用中心点比例,如下所示。但我并不满意,因为在平板电脑屏幕上问题仍然存在。
注意:
- 正如您可能已经注意到的那样,我已经在Stack Overflow上尝试了其他建议的修复方法,例如将Adjust View Boundaries设置为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选项,但似乎都不能解决这个问题。(如所见WYSIWYG编辑器中) - Dheeraj Bhaskar
您可以尝试使用android:background="@drawable/bg_gradient",并将layout_widthlayout_height设置为"match_parent",为父级LinearLayout添加背景。 - Piyush Agarwal
@pyus13 我已经尝试过了,但那并没有什么帮助。我得到了类似的结果。 而我在这里使用FrameLayout的原因是:1)我可以“合并”并消除一个视图层次结构;2)渐变、人物和品牌都是不同的图像,需要重叠显示。 - Dheeraj Bhaskar
这些图片本身有什么问题吗?我如何判断? - Dheeraj Bhaskar
3个回答

2

使用 android:background="..." 属性代替 android:src="...",希望这样可以解决问题。


1

目前我使用的方法是将这些图像原封不动地用于手机,或者为 WVGA(平板电脑)使用另一组图像(和布局?)。

虽然我还没有尝试过这个方法。我会尽快发布带有屏幕截图的文章。

编辑:看来问题出在图像本身上。有透明填充。我会请设计师修复它。 :)


0
在Eclipse中的活动图形布局中,您可以右键单击活动,然后选择“编辑背景”。这将允许您将图片设置为背景,覆盖屏幕的所有边缘。 希望这能帮到您,祝好,Jim

谢谢回答。但是它只是将背景的src设置为这个图像吗?如果有任何缺陷,仍然会显示图像的缺陷(如我在答案中发布的那样;我应该将那部分移动到问题中吗?) - Dheeraj Bhaskar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接