In my eclipse, when ever I have a scrollView and a background image set up at the same time, my background image stretches vertically. I would like it not to stretch but repeat all the way down the ScrollView.
Please help
Create a XML file within the drawable:
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/my_image"
android:tileMode="repeat" />
than you can use this file as your drawable, and it will be repeated
Note that there is a bug related to repeat (android 3.0 and bellow), when used in a listview
see XML drawable Bitmap tileMode bug?
Related
So I would like to create a checkered effect with my bitmap. So I am using this very small pixel grey color png. I need to add a margin or padding before it's repeated but I'm unsure how to do this. Any help will be welcome as I have just started learning Android development.
What it's doing right now is repeating the entire image, filling the window with one color.
Background.xml
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/bg"
android:tilemode="repeat">
</bitmap>
In my Activity Main XML I'm including the above XML
android:background="#drawable/background"
If I understand You correct and You want to make an effect like this
Using a single grey pixel and adding margin to next before repeating, it will be much easier if You don't use:
But just a:
With a pattern like this, You can repeat an image and You will get a checkered effect.
I want to apply a background image to a linear layout and I have problems because the image loose from quality when stretched.
The image is composed by the fill color and some dots pattern applied over the background.
The image was made with Adobe Illustrator (png). Also I tried using nine-patch but does not work, the dots are stretched.
Should I make this background from code(override onDraw from the linear layout)?
I'm guessing you want to repeat that pattern, not stretch it. Create a drawable resource in xml form, representing your tiled background:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:tileMode="repeat"
android:src="#drawable/background_image"
/>
My problem is a whitespace that creates itself when I put an image in the background.
I made a new icon set. Put an image there and cropped it so it has no white border. And when I create a new image view it works it has no border around itself. But when I put it as a background on repeat it creates a whitespace.
It looks like this:
I cant post an image so look here: http://i.stack.imgur.com/AwNiz.gif
I am using a relative layout and I have created a file drawable and put an xml file in it in which I have this code:
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/im"
android:gravity="center"
android:tileMode="mirror"/>
I tried it with 3 different pictures and it always does the whitespace when put on repeated background.
I wanted the background to simply connect without any whitespace.
Thanks in advance :)
I am using Eclipse.
What happens if you create a 9.png file and allow it to stretch to the edges? Looks like your bitmap is smaller than the space.
In a start activity of our android application we're using a linearlayout with an background image for whole space.
The image size is 320x480 - the same as device resolution, we're using for testing.
The problem is, the image will be scaled und looks not so nice.
I tried to use imageview instead, but I've got black borders.
Some ideas, how to avoid scaling or how to get the proper size for background image?!
Thank you in advance.
Mur.
Create a background.xml file in res/drawable and use the following:
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/background_image"
android:gravity="center"/>
And use this background.xml as your LinearLayout's background.
I have a 9-patch image file which looks like this:
When I use it it appears like this:
What I actually wanted to achieve is the complete dot in the center repeated instead of stretched. I hope that it's possible.
I think it's not possible using 9-Patch to make repeated patterns (only stretching certain area), perhaps you could find more about it in official documentation
...
Correction: If you want the orange dots to repeat, you will not succeed using 9 patch. 9 patch can only stretch the part you told it to stretch and leave untouched, the remaining areas. There is no repeat mode with 9 patch PNG.
You might want to look into Bitmap class. There is a tileMode you might be able to use for your problem here.
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/stripe_bg"
android:tileMode="repeat"
android:antialias="true"
android:dither="false"
android:filter="false"
android:gravity="left"
/>
First make sure you save your 9 patch image as your_image_name.9.png and store it in the res/drawable folder. Then in your xml just set the layout background with-- android:background="#drawable/your_image_name" and that should work. If it's still not working can you post your layout xml?