How to change size image of splash by using migrate? - android

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.

Related

How to add a custom splash screen in MAUI?

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.

Border line appear in drawable in Android

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

Please help me transform two images into 9-patch

The designer has given me two PNG images and they are supposed to be the background for all the buttons of my app. I am not being able to transform then into 9-patch image. It seems like that one image has too much details to be a 9-patch, stretching it would make it lose the details.
Can you guys take a look and let me know what you think?
http://img211.imageshack.us/img211/1965/background1p.png
http://img845.imageshack.us/img845/676/background2a.png
Many thanks,
Felipe
//repeatimage.xml
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/tileimage"
android:tileMode="repeat"
android:dither="true" >
</bitmap>
and set this image in your layout background as
android:background="#drawable/repeatimage"
//slice your image into small pieces
Try using this tool . It's a simple 9-patch generator that can be of use to you.
For both your questions:
1: I use images with shadows a lot and you can certainly convert them into a 9-patch image. I am not sure how I can explain the actual steps involved in creating this. Perhaps an example will help you work that bit out.
2: For an image with a pattern in it, a 9-patch of it as #Padma Kumar pointed out, will still distort your image. To fix that, you can follow the link attached. It is a nice tutorial on how to use tiled patterns as backgrounds. http://androidforbeginners.blogspot.in/2010/06/how-to-tile-background-image-in-android.html
A side note: The draw9patch can be quite an intimidating tool. Until you get the hang of it, you could consider using this website here: http://android-ui-utils.googlecode.com/hg/asset-studio/dist/nine-patches.html. It however, works only in Google Chrome.
Maybe you should check this tutorial: http://www.thesecretpie.com/2010/07/creating-custom-fancy-buttons-in.html
It explains how 9-patch actually works and how to use drow9patch tool which comes with Android SDK. It was really useful for me.
And for the shadows, you just need to save image with transparent background (of course) and with a little free space between shadow and edge of an image which you will use to draw lines for 9-patch

How to add a PNG image as background in Android with no alteration (banding)?

I'm trying to add a background that includes a gradient (I do want to use an image, not an android xml declared gradient effect).
This image is remarkably ruined by Android, it add some crappy banding whatever I try the result is the same (two capture of approximately the same region the distorted/normal images) :
My image is used as a layout background inside my layout XML :
android:background="#drawable/background_gradient_dithered"
I've tried to used an intermediate drawable to force dither whose xml is :
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/background_gradient" android:dither="true" android:antialias="true" android:filter="true"/>
I've tried to have the following code in my onCreate() :
getWindow().setFormat(PixelFormat.RGBA_8888);
Both tries changed nothing.
Thanks
The correct solution was .... I bet you've guess it : restarting Eclipse. I've learned it, every problem on Android might be a "restart Eclipse problem".
After some test I can add that enabling dethering is not useful when Format is set to PixelFormat.RGBA_8888
Readers should give a look to the answer given by #TenFour04, this approach can avoid to make drawable just to enable dithering.
window.addFlags(WindowManager.LayoutParams.FLAG_DITHER);
EDIT :
I've found out that even with these tricks the problem can persist. You can try to modifiy your PNG to have an alpha layer in it (change a pixel to a transparency of 99% for example), this would force android compiler to not play with it.
Try adding this in onCreate(). Older versions of Android default to no dithering.
Window window = getWindow();
window.setFormat(PixelFormat.RGBA_8888);
window.addFlags(WindowManager.LayoutParams.FLAG_DITHER);
I worked it out, just change the size of the .png files. I put them in the mdpi and resized it with Irfanview <-open source image editor to 1024x7xx <- dont remember, this comes too handy
and I set it for 300 dpi. So they download it on a tablet and stuff, hope this helps :)

Tiled drawable sometimes stretches

I have a ListView whose items have a tiled background. To accomplish this, I use the following drawable xml:
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/tile"
android:tileMode="repeat" />
Usually, this works. Sometimes, however, the src drawable isn't tiled, but stretched to fill the entire list item. (I've got several different tiles like this, and I use them mixed in one ListView. If there is stretching instead of tiling, it's never been in all of them at once, for what that's worth.)
I also tried to add android:dither="true" to that xml, since I read somewhere that without it there might be bugs. That didn't change anything.
Has anyone had the same problem? How did you fix it?
I also got bitten by this problem. Very hard to diagnose, even harder to find similar reports and usable solutions.
"Tapas" on the freenode #android-dev irc channel came with the following utility method:
public static void fixBackgroundRepeat(View view) {
Drawable bg = view.getBackground();
if (bg != null) {
if (bg instanceof BitmapDrawable) {
BitmapDrawable bmp = (BitmapDrawable) bg;
bmp.mutate(); // make sure that we aren't sharing state anymore
bmp.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
}
}
}
Apply it to all Views that have a tiled background set (e.g. findViewById them).
Also, I have the impression this bug started acting up after setting "anyDensity=true" in AndroidManifest.xml
I've just had the exact same issue except with CLAMP TileMode. I have a bitmap that I want to then just stretch away at the bottom and have it set up as an XML defined BitmapDrawable and in the Graphical Preview window all looks fine, no matter what size I make the ViewImage it draws my bitmap at the top and then repeats the last pixels to fill to the end.
Launching the app on various SDK builds on the emulator and on my own phone all then produced a straight 'fill' type distortion which is completely useless.
The solution turned out to simply be to re-apply the TileMode every time I changed the size of the ImageView within my code:
((BitmapDrawable)ascender.getDrawable()).setTileModeY(TileMode.CLAMP);
Now it's all drawing fine. So yes, this looks like a bug to me.
As I didn't see the link here, this was confirmed to be a bug in Android. It was fixed in ICS. See XML drawable Bitmap tileMode bug? for more details.
There is a lot of noise about this topic online, with various (and numerous) suggested solutions.
If you're still at a loss, my suggestion is to keep all tiled bitmap
resources to square, base-2 dimensions.
ie: 16px by 16px for an xhdpi tile asset.
I hoped that the Android platform would "over-tile" to fill a space if the bitmap did not tessellate perfectly - and then trim the waste. However trialling a 10px*10px tiled bitmap across mdpi, hdpi and xhdpi (and v2.3 to v4.0)'inconsistently' showed this stretching.
The base-2 dimension allows for whole and even division as you progress through the various resolutions and as each device tries to paint the tiles each time the view is created.
In Android development, we contest with the ranging hardware and the vendors dipping their fingers into the platform - sometimes this sort of trivial black magic just works.
This appears to have resolved the issue for me at least. Worth a shot.
This sounds like a bug, although I've never seen it myself. If you have a simple APK that reproduces the issue, please send it to me (romainguy /at/ android.com) or file a bug here.
This blog entry discusses the issue
combined with this solution from Tapas listed by Ivo van der Wijk, it works for me.
The key was to remove the tiled setting from the XML, then set it to tiled at runtime. It does not work for me if they are both set to tiled.
Edit: actually, I lied. Even with this it seems to sometimes fail to tile.
Would be very nice to have a reliable work-around.
Edit 2: setting it to something else (eg. CLAMPED) then setting it back so far seems to be working.
I moved my image from drawable-xhdpi to drawable folder and everything was fine.
I was also having the same issue. What I was missing was that we need to add scaletype to fitXY in the imageview for the xml bitmap to work properly.
tile_bitmap.xml
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/tile"
android:tileMode="repeat" />
layout.xml
<ImageView
android:layout_width="match_parent"
android:src="#drawable/tile_bitmap"
android:layout_height="match_parent"
android:scaleType="fitXY"/>

Categories

Resources