0

我正在使用 API 16 (Jellybean)、4.0 WVGA (480x800: hdpi)

我正在尝试在背景中设置 480x800 图像

我将图像放在“drawable-hdpi”中,但该图像不适合背景,为什么当我使用 4.0 WVGA(480x800:hdpi)并且与图像大小相同时这不适合背景

drawable 如何适应图像:

这是我的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.newapp.Firstscreen$PlaceholderFragment" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:src="@drawable/background" />

</RelativeLayout>

看截图:

http://s15.postimg.org/u8rkm6rhn/frghfghfgh.png

4

3 回答 3

1

更改Height和到。Width_ImageViewmatch_parent

<ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/background" />

编辑-

完整代码——

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.newapp.Firstscreen$PlaceholderFragment" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/background" />

</RelativeLayout>
于 2014-03-20T09:44:29.057 回答
1

你可以这样做

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"     
    tools:context="com.example.newapp.Firstscreen$PlaceholderFragment" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_paren"
        android:layout_height="match_paren"
        android:scaleType="fitXY"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:src="@drawable/background" />

</RelativeLayout>

或者

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:background="@drawable/background"
        tools:context="com.example.newapp.Firstscreen$PlaceholderFragment" >
<!-- CONTENT HERE -->
</RelativeLayout>
于 2014-03-20T09:44:39.763 回答
0

将此行添加到您的 ImageView

 android:scaleType="fitXY"

并将宽度和高度设置为 match_parent。

于 2014-03-20T09:47:18.853 回答