4

I have an ImageView inside a RelativeLayout. the ImageView's source is a .png file. The problem is that android is not scaling the image up or down when tested on devices with different resolutions. I read in the android documentation that android automatically scales the image up or down to fill the screen, but this is not happening. What could be the problem? I'm new to android, sorry if this question is dumb, I searched a lot but couldn't find a solution.

EDIT: The XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
     >

<ImageView
        android:id="@+id/imageview1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_centerInParent="true"
        android:clickable="false"
        android:scaleType="fitXY"
        android:contentDescription="@string/p"

        android:src="@drawable/example" />
</RelativeLayout>

EDIT 2: The XML layout I need to stretch:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:theme="@android:style/Theme.Black.NoTitleBar" 
    android:gravity="center">

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/imageView1"
        android:clickable="false"

        android:contentDescription="@string/p"

        android:src="@drawable/volbar" />



    <ImageView

        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="false"
        android:layout_alignParentLeft="true"
        android:contentDescription="@string/p"

        android:src="@drawable/head" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imageView1"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="33dp"
        android:layout_marginRight="19dp"
        android:text="@string/press_to_update" />

    <ImageView
        android:id="@+id/imageView9"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/imageView2"
        android:clickable="false"
              android:contentDescription="@string/p"

        android:src="@drawable/frag11"
         />

    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"

        android:layout_below="@+id/imageView9"
        android:clickable="false"
        android:contentDescription="@string/p"

        android:src="@drawable/base" />
    </RelativeLayout>
vergil corleone
  • 1,091
  • 3
  • 16
  • 34

3 Answers3

11

use android:scaleType="fitXY" in the layout

EDIT

if you want the image to occupy whole screen then use

    android:layout_width="match_parent"
    android:layout_height="match_parent"
stinepike
  • 54,068
  • 14
  • 92
  • 112
1

Refer this,

**

<ImageView
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:background="@drawable/ic_launcher"
                ***android:scaleType="fitXY"***
                android:layout_alignParentRight="true"
                />

**

ImageView won't fill parent

Hope this helps...

Community
  • 1
  • 1
Ramesh Sangili
  • 1,633
  • 3
  • 17
  • 31
0

android:layout_width="match_parent"

android:layout_height="match_parent"

 >

    android:id="@+id/imageview1"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:clickable="false"

    android:contentDescription="@string/p"

    android:background="@drawable/example" />

Aydroid
  • 81
  • 1
  • 4