Ambran
Ambran

Reputation: 2627

Android: Set image som background

There are quite a few questions regarding background images, but I couldn't find a solution to my problem.

What I need is simple: I have an image i landscape orientation, and I would like it to the background of an activity where it always takes parent height but free in width and of course keep the image ratio. That way it will match the app's portrait and landscape orientations.

I've tried (I think) all layout possibilities, but allways get the image shrinked to the screen size thus wraking it's aspect ratio.

I need the parts of the image to go out of the screen if the image is wider but always take the whole height of the screen.

Any ideas?

Upvotes: 0

Views: 50

Answers (2)

Nandhu
Nandhu

Reputation: 68

Use scaleType property to your image.

please refer this link for different types of image scale Type property.

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

Upvotes: 0

Ichor de Dionysos
Ichor de Dionysos

Reputation: 1137

How about using a FrameLayout as root View and set a Iamge View inside with the attributes:

android:src="@drawable/your_image"
android:scaleType = "centerCrop"

I think this should work for you!

Upvotes: 1

Related Questions