ImageView的不拉伸以适应屏幕

ImageView的不拉伸以适应屏幕

本文介绍了ImageView的不拉伸以适应屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可绘制的,它需要为背景,以工作。它需要拉伸以填充屏幕(忽略宽高比)。

我已经提供了LDPI,MDPI,华电国际和xhdpi适当的大小。
(我知道他们是适当的由相应的宽度和高度的比例,是否足够呢?)

我试图做到这一点如下:

使用scaleType:fitXY上的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 elsewhereon SO like setting Adjust View Boundaries to true. They didn't helphere. :(
  • 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).

Edit: Figures it had to do with the images themselves. There was transparent padding. Will ask designer to fix it. :)

这篇关于ImageView的不拉伸以适应屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 21:08