Alex Rivera | Logout

Background image for wrap_content

Asked 2010-09-06T02:39:42.743
12

I created a custom background image and wanted to use it as the background for a layout that has height of wrap_content. However, the total height of the contents of within that layout are much less than the height of the background image.

When I set it as the background in XML via android:background="@drawable/image", I noticed that it displays the entire height of the image, although the height of the actual contents are much shorter.

Is there a way to stop this from happening?

Thanks.

Edit
Report

1 Answer

0

I also faced this problem. If you set the background's resource is too small, you might have problems with aspect ratio. The solution I found was to divide the background's image in three parts: top, middle and bottom. Each of these images are backgrounds of three different Layouts/ImageViews. The middle part is the one that holds the "wrap_content" property:

Top: bg_top

Middle: bg_middle

Bottom: enter image description here

As the content's size increase, the borders will keep unaffected and the middle will increase as well (as will the whole "box"). Of course, this is a solution for a case that the partition of your background's image makes sense.

answered 2012-01-10T13:27:35.000

Your Answer