Question

i am using API 16 (Jellybean), 4.0 WVGA (480x800: hdpi)

and i am trying to set a 480x800 image in background

i put a image in "drawable-hdpi" but this image is not fitting in background, why this is not fitting in background when i am using 4.0 WVGA (480x800: hdpi) and same as image size

how drawable works to fit image:

this is my code:

<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>

see screenshot:

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

Was it helpful?

Solution

You could either do it this way

<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>

OR

<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>

OTHER TIPS

Change Height and Width of ImageView to match_parent.

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

Edit-

Complete code-

<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>

Add this line to your ImageView

 android:scaleType="fitXY"

and set the width and height as match_parent.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top