views:

36

answers:

1

Hello,

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.

A: 

You can convert your background image to 9-patch drawable or use XML bitmap to alter behavior of your image when it is greater then the container. See http://developer.android.com/intl/zh-TW/guide/topics/resources/drawable-resource.html page for more info about both.

Konstantin Burov
Could you elaborate more on this if using a XML bitmap? I tried using a XML bitmap and used the property android:gravity="top|fill_horizontal|clip_vertical" to see if that will solve the problem, but it still does not.
Well, I didn't tried XML bitmap for the case like yours, but the options look promising. The 9-patch way will work for sure -- I've used that already.
Konstantin Burov
Hmm. I've tried all of the options that might help, but I think I may be doing something wrong. I've searched everywhere online and nobody seems to be having this problem...
Then try 9-patch :)
Konstantin Burov