Markus
Markus

Reputation: 2574

ImageView which overflows its parent

I have a RelativeLayout which I expand (vertically) when clicked on. This RelativeLayout have a background image. This is implemented by adding a ImageView to the RelativeLayout.

I want the Image (and ImageView) to be larger than the RelativeLayout, so when the RelativeLayout is expanded the background (ImageView) is not stretched but instead just showing a larger crop of ImageView.

I would really like to have a ImageView larger than the RelativeLayout and then just expand the RelativeLayout instead of changing the size of the ImageView when the RelativeLayout is expanded. The reason for this is that the expansion uses a smooth animation and changing the ImageView for each frame leads to a significant overhead since it resizes/crops the image for each frame to match the current size of the RelativeLayout.

Upvotes: 1

Views: 2034

Answers (1)

Phantômaxx
Phantômaxx

Reputation: 38098

Contained Views can't be bigger than their parents.
But the image in an ImageView can be bigger than the View.

Just don't set it as a background (which will be stretched), but as a src.

NO:

android:background="@drawable/my_bg"

YES:

android:src="@drawable/my_bg"

You can play with the scaleType attribute (http://developer.android.com/reference/android/widget/ImageView.ScaleType.html) for fine tuning

Upvotes: 1

Related Questions