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"
..........>
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 an SVG that I'm using as the foreground for my adaptive icon. It's height and width are 128px128px. But when I go to drawable>New>Vector Asset and create an XML my viewportWidth is disproportionately large.
My icon instead of being nested inside my background instead takes up the whole page and cover even the background. I tried using Inkscape and reduced the size of my SVG and sent it through drawable>New>Vector Asset again, but my icon is still gigantic, covering everything...but it's just a blurry blob.
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="128dp"
android:height="128dp"
android:viewportWidth="1280"
android:viewportHeight="1280">
When creating Vector from drawable>New>Vector Asset check Override option and put your desire size.
Don't use SVG for icon. Download the highest resolution png for your icon.
Then add that to your minmap directory. It will automatically generate icons of all sizes.
Right click on minmap - > Image asset
There you can position the icon
I have a drawable object which contains a app icon and it is stored it in runtime process.when I test it in different screen size it gives me different app icon size .I want my drawable object to give a same constant size of app icon weather it is running in big screen size or small screen size it should give same size app icon.Is it possible.
If you want to add images for different screen size you can simply following steps:
Right clik your on app>New>Image Asset
Select Asset Type: Image and browse your logo or image you want to use
Rename your image
Click next and finish
You can find your image in mipmap with images that are for all kind of screen sizes
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?
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>