S.Queroane
S.Queroane

Reputation: 87

how to make imageView take match parent of relativelayout

i'm trying to make ImageView take match_parent of RelativeLayout like this picture :

enter image description here

when i run my app ImageView looks like that :

enter image description here

this my xml :

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linealL"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/khdar">
    <RelativeLayout
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_margin="10dp"
        android:id="@+id/RelativeLayout02"
        android:layout_width="wrap_content"
        android:background="@color/colorGriviewBorder"
        android:layout_height="wrap_content" >
        <LinearLayout
            android:layout_margin="5dp"
            android:id="@+id/LinearLayout01"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/gradient"
            android:orientation="vertical" >
            <TextView
                android:text="GIF"
                android:textSize="16sp"
                android:layout_gravity="center"
                android:textColor="@color/colorGriviewBorder"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/dev"/>
        </LinearLayout>
        <ImageView
            android:padding="8dp"
            android:layout_below="@+id/LinearLayout01"
            android:contentDescription="@string/app_name"
            android:id="@+id/imageSelectTo"
            android:scaleType="fitXY"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"/>
    </RelativeLayout>
</RelativeLayout>

Upvotes: 0

Views: 1742

Answers (3)

Xenolion
Xenolion

Reputation: 12735

If you want to fit the ImageView width then You have to ignore height. And by default will not strech for you to keep aspect ratio, so you need to add another attributes for adjust view bounds. So lastly you will have your code chages as follows for an ImageView:

 android:layout_width="match_parent"
 android:adjustViewBounds="true"

The adjust View bounds will adjust to a particular height while keeping the aspect ratio.

More

Also to avoid future mistakes again in your code you have nested two RelativeLayout's which I guess is due backgrounds. If there is no need for that If do not care about space. The inner RelativeLayout View height and width should be set to match_parent!. Happy Coding!

Upvotes: 3

Łukasz Kobyliński
Łukasz Kobyliński

Reputation: 1111

Change layout_width of ImageView to match_parent and add one new attribute to it: android:adjustViewBounds="true".

Upvotes: 4

Fargonaut
Fargonaut

Reputation: 791

Your ImageView's layout_width and layout_height are set to wrap_content instead of match_parent.

Upvotes: 2

Related Questions