Nick
Nick

Reputation: 3435

android layout large image

I have a large image myImage.png (its dims are 1536 x 784):

Fig. 1

I want this image to be placed at the bottom of my layout scaled uniformly and fitting the width:

Fig. 2

Layout is

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

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/myImage"
        android:adjustViewBounds="true"
        android:layout_alignParentBottom="true"
        android:scaleType="fitCenter" >
    </ImageView>

</RelativeLayout>

I've tried dozens of combinations for layout_width, layout_height, adjustViewBounds and scaleType and nothing helped: it always looks as follows:

Fig. 3

Help me please.

Upvotes: 0

Views: 327

Answers (3)

Chronos
Chronos

Reputation: 1962

As someone says, use src instead of 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" >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/myImage"
        android:adjustViewBounds="true"
        android:layout_alignParentBottom="true"
        android:scaleType="fitCenter" >
    </ImageView>

</RelativeLayout>

Upvotes: 2

SubbaReddy PolamReddy
SubbaReddy PolamReddy

Reputation: 2113

try this:

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/myImage"
    android:adjustViewBounds="true"
    android:layout_alignParentBottom="true"
    android:scaleType="fitcenter" >
</ImageView>

Upvotes: 0

njzk2
njzk2

Reputation: 39386

You are using an ImageView. ImageViews use the src attribute to indicate which image to use and to apply the scaleType to.

background, is, as name suggests, merely a background attribute, made to be displayed on that whole background thing.

Upvotes: 1

Related Questions