I need to set background of repeat image.
So i have a file repeat_dark_bg.xml in my drawable folder
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/repeat_dark_marked"
android:tileMode="repeat"
>
</bitmap>
repeat_dark_marked - image, which i want to repeat.
so then i use repeat_dark_bg.xml as background value of my linearlayout.
but whats a problem.. when i test my app on device sometimes image repeat_dark_marked repeat, sometimes it scales and resizes to full screen.. i cant understand why sometimes it shows this or that.. any ideas?
repeat_dark_marked.png is 9-patch ? make sure you dont have multiple repeat_dark_marked.png or repeat_dark_marked.9.png etc in your drawable folders. Check all drawable-mdpi, drawable-hdpi, drawable-ldpi folders.
Related
I am trying to show the repeated background in the layout. When I use the bitmap resource it can use only one image. So, I have the same size photo(48x48 in my case)in all screen. But I want to show image depends on screen size as we do in launcher icon. I have five images in mipmap folder and how can I use these images?
Following is my code,
res/drawable/repeated_background.xml
<resources>
<bitmap
xmlns:android=http://schemas.android.com/apk/res/android
android:src="#drawable/background_img.png"
android:tileMode="repeated"/>
</resources>
res/layout/activity.xml
<RelaytiveLayout
............
android:background="#drawable/repeated_background"
..........>
This is screenshot when i was trying to set gradient in android studio
here is my code for set backgourd image as pattern -
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#mipmap/ic_bg_pattern"
android:tileMode="mirror" />
and i applied this XML file into the activity_main.xml file
android:background="#layout/backrepeat"
Note:- the image i was added from image asset.(but when i copy and directly paste it was working fine)
In My Case this works
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/single_img"
android:tileModeX="repeat"
android:tileModeY="repeat"
/>
#Abhishek answer is also correct but this is problem occurs when we try to use a patter image with some low pixels means 50x50Px so the image is not android draw the small image as tile format so we see clearly the black space if we use some big image like above 150*150px then it create the good texture that you want to use.
Hello I am trying to get Nine patch drawable from this tool Android Asset Studio, it generated the drawables of different density and that drawable I am setting as background of the button but drawables it generated has border line around images in four side that appear also when I am trying to run application in device.
Why it is so and can you please tell how this can avoided ?
<Button
android:id="#+id/submitButton"
android:layout_width="match_parent"
android:contentDescription="#null"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/sign_up_views_vertical_top_margin"
android:background="#drawable/sign_up_via_email_selector" />
sign_up_via_email_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/sign_up_submit" />
</selector>
Thanks in advance
Check to see if the image has the correct name.
It should be sign_up_submit.9.png, the lines that appear are actually the areas that the 9patch defines for stretch.
If the image has the correct name it is a chance that the online utility application you used messed the resource. Try to use the 9patch generator from the android sdk(look for [your_sdk_path]\tools\draw9patch.bat), and try to generate one yourself and see if the problem is still there.
can you please check how you placed your 9 patch image in drawable folder,9 patch image should be named sign_up_submit.9.png
I have a few buttons in my app where I have applied circular PNG images on them but the edges gets pixelated. I don't know how to nine patch a circular image. If anybody knows a different way of doing it?
you can use following code to have circle image:
add this on drawable folder
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#2085c226"/>
<stroke android:width="2sp" android:color="#85c226" />
</shape>
then in your code
android:background="#drawable/name_of_xmlfile"
One reason why android may try to scale your images is if you don't have them ready for your screen density. Make sure that you have your png image in res/drawable-xxhdpi, res/drawable-xhdpi, res/drawable-mdpi - all screen densities you are planning to support.
Note that xxhdpi is not mentioned in android documentation and the folder is not created by default but you need it if you are planning to support xxhdpi screens.
You didn't provide enough information e.g screen shot? code? but any ways you should use nine patch images if you are not providing separate image in each drawable directory. For further detail Go to This link. Hope this will help you.
I have the following testbackground.xml file:
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/popup_light_background_img_small"
android:tileMode="repeat"
android:dither="true"
/>
Which when set as a background creates a repeating background image.
#drawable/popup_light_background_img_small is a 64x64 image, but If I replace it with an image which is 100x100 pixel then the background will not repeat. It just show the image once, and then repeat the last pixel in the image, instead of the entire image. Anyone who have idea about why that is?