I am trying to set a 9-patch image as the background for one of my activities but it is stretching unescessarily making everything get all wierd. I used draw9patch to create it and added one pixel to the bottom left and one pixel to the top right. I then save it into my drawables directory as intro_bg.9.png. I want to stretch the very bottom and stretch the far right side but only if it has too. If it doesn't then I would like it to stay in tact.
When I set it as the background of the parent layout however it stretches it both horizontally and vertically and it doesn't even show my buttons when I run it on my droid.
I've done the Google searches but there is no good info on how to get something like this working. What am I missing?
I have also tried some other configurations including using the padding sides(right and botto开发者_JAVA技巧m) but that gave the same results.
Thanks
Code to set as background:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/intro_bg"
>
Looks like:
Should look like:
Your image is just too big to fit the layout. If you want it to be contracted you need to paint a line on the top and left borders -- the line marks region which will be contracted or stretched. I guess right now you have just dots on the borders.
Second option is to set the image as activity background, then it will be fitted in the screen. To do this add styles.xml to res/values folder:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="ExampleTheme" parent="android:Theme">
<item name="android:windowBackground">@drawable/intro_bg</item>
</style>
</resources>
Then apply the theme to your activity at the manifest. The intro_bg drawable even doesn't need to be a 9-patch.
精彩评论