iamjc015
iamjc015

Reputation: 2245

Imageview not matching the width of Linearlayout

I have a layout in which a linearlayout contains imageview as its direct child. I want to fit the width of this imageview so that it spans horizontally to match the size of the parent which will take the width of the whole screen.

How can I do that? This is what i've done so far:

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:id="@+id/linearLayout"
        >


        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="100dp"
            android:layout_margin="0dp"
            android:src="@drawable/policemen_salute"
            android:id="@+id/banner"
            />



    </LinearLayout>



</RelativeLayout>

It looks like this

enter image description here

Thanks!

Upvotes: 0

Views: 275

Answers (4)

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75788

You can use android Scaletype Property .

android:scaleType="fitXY"

Then set android adjustviewbounds true from XML .Try this way I hope it will helps you.

Upvotes: 2

Mateus Brandao
Mateus Brandao

Reputation: 900

You have to use a scaleType to scale correctly the image. try your ImageView like this:

<ImageView android:layout_width="fill_parent" android:layout_height="100dp" android:layout_margin="0dp" android:src="@drawable/policemen_salute" android:id="@+id/banner" android:scaleType="centerCrop"/>

Upvotes: 2

Renan Arceno
Renan Arceno

Reputation: 600

Add the 'scaletype' attribute:

<ImageView
        android:layout_width="fill_parent"
        android:layout_height="100dp"
        android:scaleType="fitXY"
        android:layout_margin="0dp"
        android:src="@drawable/policemen_salute"
        android:id="@+id/banner"/>

See http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

Upvotes: 2

SuperFrog
SuperFrog

Reputation: 7674

If you wish to scale your image, you might want to add

android:scaleType="fitXY"

(Scale in X and Y independently, so that src matches dst exactly) to your ImageView

<ImageView
            android:layout_width="fill_parent"
            android:layout_height="100dp"
            android:layout_margin="0dp"
            android:scaleType="fitXY"
            android:src="@drawable/policemen_salute"
            android:id="@+id/banner"
            />

Upvotes: 1

Related Questions