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.
Related
I have a basic MAUI project and I want to set an SVG file as the splash screen.
I have tried to modify the csproj file using the code below:
As you can see the photo is cropped in a circle
How can I make the splash screen display the entire photo?
You cannot (at least not without going a long way using a separate splash screen activity).
That's a limitation of Android: https://developer.android.com/develop/ui/views/launch/splash-screen
The picture also needs to fit into the frame and should be squared. You can set the base size for that in the <MauiSplashSceen> build action in your .csproj file.
You may also be interested in this: Custom NET MAUI Splash screen
There currently also is a bug in MAUI's resizetizer which requires giving the SVG file an entirely new name each time you want to change it: https://stackoverflow.com/a/74336491/4308455
I've written a blog post about the Splash Screen in MAUI, which might also be of interest: https://ewerspej.hashnode.dev/lets-customize-the-splash-screen-of-a-maui-app
For the device which android version is lower than 12.0, you can use the following code to make the image full full the splash screen.
Delete the old splash image in the Resources/Splash folder.
Put your image in it and set it's build action as MauiSplashScreen
Create a xml file in the Platforms\Android\Resources\drawable\maui_splash.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
<item>
<bitmap
android:src="#drawable/splash" //the splash is your image's name
android:dither="true"
android:gravity="fill"/>
</item>
</layer-list>
And then, your image will show in the full splash screen.
For the device which android version is lower than(or =) 12.0, the android system changed the api about the splash screen. The resource code about is the FrameLayout contains a ImageView and we can't set the ImageView layout_width and layout_height. For more information, you can check the answer in this link.
I have the following design and need to make without using png file if possible. I have done this with the help of png file but i am thinking if there is any other way which is performance centric.
I have done this design with the help of png file
https://pasteboard.co/Is3RtJY.png
How do i draw this myself or use some tool to get this done?
Use the following code to create this custom shape bg_top_corners_round.xml and save it in your drawable:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/white" />
<corners android:topLeftRadius="16dp" android:topRightRadius="16dp" />
</shape>
Then use this drawable in any of your layout XML files, inside CardView/TextView/ImageView like this:
android:src="#drawable/bg_top_corners_round"
PNG images are good for application but, Another option you can use in your application is that you can use webp type images instead of png, which is very smaller in size so, it will help in decreasing the apk file size of the application.
In the android studio you can convert png image to webp image. Another best thing you can do is convert png to related vector graphic(SVG) and then import that SVG as drawable. Like for png and webp images you will not needed to add images according to device density but it will be automatically maintained means when the image will be needed it will be drawn according to the device density.
Many websites are available which can help to convert the png to SVG but I prefer https://www.vectorizer.io/
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 an activity in my Android application like the image below:
legend:
gray: background image covering the whole screen;
blue: 5 different sized circles;
green: an arbitrary image;
I was animating the circles using the View Animation (http://developer.android.com/guide/topics/graphics/view-animation.html) to show only one at time.
But I got OutOfMemory exception in some devices and emulators that I used to test.
I changed my layout to use 3 ImageView instead, one with one image of the 3 inner circles, and the others with the 1 outer circle each using the same image file but with different sizes, and I am animating them enabling and disabling their visibility property. Thus I'm using only 2 images instead of 5.
With this approach I stopped getting OutOfMemory exception, I guess because I am loading and displaying less images than before.
FYI, I have different image sizes placed in the folders:
drawable-hdpi
drawable-ldpi
drawable-mdpi
drawable-xhdpi
Is the memory that limited?
Has anyone have a better solution to suggest so I can keep using my 5 circle images?
The application is small so there is no point in going to the path of using OpenGL.
Thanks!
Yes, the Android system only guarantees 16MB of memory for one application, but manufacturers can allow more (usually they do). But they are not restricted to do so, so if you exceed this limit, you can get OutOfMemoryException on a lot of devices with low memory.
If it's really just circles, you won't need actual bitmap images for them but can use a ShapeDrawable instead. This would save all the memory for the circle images (and would result in perfect circles in all resolutions).
A simple example from another SO item:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
<gradient android:startColor="#FFFF0000" android:endColor="#80FF00FF"
android:angle="270"/>
</shape>
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.