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?
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 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"
..........>
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 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.