0

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

user3441251
  • 27
  • 2
  • 7

3 Answers3

1

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>
Kanwaljit Singh
  • 4,339
  • 2
  • 18
  • 21
1

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>
A.S.
  • 4,574
  • 3
  • 26
  • 43
0

Add this line to your ImageView

 android:scaleType="fitXY"

and set the width and height as match_parent.

suresh kumar
  • 193
  • 1
  • 10