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
Related
I I try to make splash screen by using migrate. But I do not change resize image that I used. Here is my picture.
What I do:
implementation 'androidx.core:core-splashscreen:1.0.0-beta02'
I added this implementation to gradle.
I made theme part like
this
I put this theme in manifest.
Finally, I added this in main activity
I hope, someone can solve this problem.
I used a layer-list to resize my app logo:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="288dp"
android:height="288dp"
android:drawable="#color/splash_screen_background" />
<item
android:drawable="#drawable/app_logo"
android:gravity="center" />
</layer-list>
The library specs can be found here
That image seems too small and possibly should be round with transparent background. In the alpha version, the scaling still worked differently and when upgrading from there, the image didn't fit anymore. Would need to look it up, because one can find the perfectly correct (as expected by the library) dimensions of the splash screen image in the library resources. My code looks like this:
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
SplashScreen.installSplashScreen(this);
}
One would commonly use Photoshop or GIMP to change the size of the image (it's predefined). Using a vector drawable XML (similar to SVG) instead of PNG or WEBP scales nicely. And please don't post screenshots of code or errors; to show visual problems that's fine.
I am using below code. "#drawable/ic_keyboard_arrow_down_black_24dp" is vector image and below you can see xml for bitmap and also you can see Error in screen shot thanks .
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/ic_keyboard_arrow_down_black_24dp"
android:tileMode="repeat"/>
to use vector image you have to set the attribute with srcCompat as:
xmlns:app="http://schemas.android.com/apk/res-auto"
app:srcCompat="#drawable/ic_keyboard_arrow_down_black_24dp"
But since src is the required attribute of the bitmap and you can not set vector image to src. Thus you have to use .png or any other image type.
Did you try running/building the app. Often you can have the automatic xml renderer fail however the app will still build fine.
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.
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.
My application crashes when i put background line like in this code. When i delete this line my application works fine and also when i use another photo it also works. What's the problem?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/table2" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
The background for the main screen works fine also. But in the second page, it is problamatic.
If you are using only drawable folder to store all images.then change storage folder for high resolution images in drawable-xhdpi folder or higher.
Hope this helps.
Thanks to you all. I changed the dimensions from 2500x1900 to 1280x920, now it works.
Make sure about the image path if it is in drawable folder..put it inside Mipmap folder in your project directory.
I think you should check the size of your image anything above 300kb may tend to constantly crash your app. You can always use image compression Softwares to reduce the size of your image.