【问题标题】:imageView is not stretching to fit the screenimageView 没有拉伸以适应屏幕
【发布时间】:2013-01-04 20:31:04
【问题描述】:

我有一个drawable,它需要作为背景。它需要拉伸以填满屏幕(忽略纵横比)。

我为 ldpi、mdpi、hdpi 和 xhdpi 提供了合适的尺寸。 (我知道它们对应的宽度和高度的比例是合适的,够了吗?)

我已尝试按如下方式执行此操作:

在 imageView 上使用 scaleType:fitXY

这确实会在 imageView 周围(内部?)留下一个白边。

我不满意的解决方法是使用 center 作为 scaleType,如下所示:

我不满意,因为平板电脑屏幕上仍然存在问题。

注意:

  • 您可能已经注意到,我在其他地方尝试了建议的修复 在 SO 上,例如将 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 选项,但似乎并没有解决它。 (如在所见即所得编辑器中所见)
  • 您可以尝试通过使用android:background="@drawable/bg_gradient" 和layout_width 和layout_height 等于"match_parent" 为父LinearLayout 本身添加背景。
  • @pyus13 我已经尝试过了,但这确实没有帮助。我得到了类似的结果。我在这里使用 framelayout 的原因是:1)我可以“合并”并消除一层视图层次 2)渐变、人、品牌都是需要重叠的不同图像
  • 图片本身有问题吗?我怎么知道?

标签: android


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    我现在要做的就是将这些图像集用于手机,也许将另一组图像(和布局?)用于 WVGA(平板电脑)。

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

    编辑:与图像本身有关的数字。有透明填充物。会要求设计师修复它。 :)

    【讨论】:

      【解决方案3】:

      在eclipse中activity的图形化布局中,可以右键activity,然后选择“edit background”。这将允许您将图片设置为背景,覆盖屏幕的所有边缘。 希望这会有所帮助,吉姆干杯

      【讨论】:

      • 感谢您的回答。但是它不只是将背景的src设置为这个图像吗?如果有的话,仍然显示图像的缺陷。 (如我的回答中所述;我应该将该部分移至 Q 吗?)
      猜你喜欢
      • 2011-06-07
      • 1970-01-01
      • 2012-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-01
      相关资源
      最近更新 更多