Android tiling a background image: using a Bitmap resizes the image?
I'd like to have a tiled background in a layout I've created, in the x-direction. I've followed some good instructions found online to tile correctly, but the source image is now stretched vertically a good bit. I think it has to do with the nature of bitmap filetypes.
Example picture:
The first image is the background image before tiling. The second image is after tiling. As you can see, the image is stretched vertically a good bit, and also appears a bit blurry due to the resizing.
I've tried placing the images in both the drawable-hdpi and drawable folder. I've tried placing the XML file in both folders. None of that seemed to matter.
Here is the code for the layout that generated those two images:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:background="@drawable/bg" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:background="@drawable/bg_repeat" />
</LinearLayout>
"@drawable/bg" is the actual image itself, bg.png. "@drawable/bg_repeat" is the following bitmap XML file:
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/cdetail_bg_unclaimed_details"
android:antialias="false"
android:dither="false"
android:filter="false"
android:gravity="center|center_vertical"
android:tileMode="repeat" />
Is there an alternative to this for x-repeat tiling? Or is there some workaround that I haven't examined yet? I've changed all of the options for antialias, dither, filter, etc. Nothing seemed to change anything.
Thanks for the help!
EDIT: This appears to be a bug using the Graphical Layout tool. It looks OK on my phone.
kindly check these links : Link1
Link2
hope these will help you!!!
This appears to be a bug using the Graphical Layout tool. It looks OK on my phone.
You can't repeat a bitmap background in one-direction using xml but Java code surely can do that.
BitmapDrawable bitmap = (BitmapDrawable) getResources().getDrawable(R.drawable.image);
bitmap.setTileModeX(TileMode.REPEAT);
So now if you set this "bitmap" to any view's background
For example: If we have a TextView "text" then text.setBackgroundDrawable(bitmap) will set the background of this text-view
to "bitmap".
It will repeat in x-direction but will preserve its height in y-direction
Hope this helps.
链接地址: http://www.djcxy.com/p/31478.html