Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android crop ImageView inside parent RelativeLayout

I would like to know how can I crop a ImageView that have a scaled background image using a fixed width and height on it's parent.

Basically, I want an image to be scaled using ImageView android:background and then I want to crop the portion of the image that is outside the parent's bounds.

Until now, I have this code:

<RelativeLayout android:id="@+id/time_foregrd"
    android:layout_width="57px"
    android:layout_height="100px"
    android:layout_marginLeft="100px"
    android:layout_marginTop="285px"
    android:clipChildren="true"
   >
    <ImageView  android:layout_width="57px"
                android:layout_height="338px"
                android:minWidth="57px"
                android:minHeight="338px"
                android:background="@drawable/time_foreground"
                />
</RelativeLayout>

But it doesn't work... What am I doing wrong?

like image 264
Cristiano Santos Avatar asked Oct 03 '22 04:10

Cristiano Santos


1 Answers

Ok, I managed how to do that. Instead of using RelativeLayout, I used FrameLayout and it worked perfectly.

Here's the code:

<FrameLayout android:id="@+id/time_foregrd"
    android:layout_width="57px"
    android:layout_height="100px"
    android:layout_marginLeft="100px"
    android:layout_marginTop="285px"
   >
    <ImageView  android:layout_width="57px"
                android:layout_height="338px"
                android:layout_gravity="bottom"
                android:scaleType="fitXY"
                android:src="@drawable/time_foreground"
                />
</FrameLayout>
like image 57
Cristiano Santos Avatar answered Oct 07 '22 18:10

Cristiano Santos