Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Background image for wrap_content

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.

like image 498
user440308 Avatar asked Sep 06 '10 02:09

user440308


1 Answers

I had a similar problem and was using a 9patch. The full 9 patch image was showing as a background even though the content it was attached to wasn't that big (was using wrap_content). I'm not sure why Android chose to show the full image instead of scaling the background to fit the content.

However, I fixed the problem by scaling down my background image. By that I mean preserving the corners but scaling down the vertical and horizontal portions. See the attached images of the background frame I had before and the result of the resize effort.

alt textalt text

like image 58
Steven Pena Avatar answered Sep 18 '22 09:09

Steven Pena