Use non-fullscreen image for splash screen - android

I'm using the approach described in Creating a Splash Screen. It uses a resource (layer-list) with a background and an image. That is used as windowBackground in a theme and this theme is set on an activity. Now I created all drawable folders and put images of different sizes in there.
Now I have these issues:
starting app in landscape on smart phone leads to a black splash screen (on tablet it stays in portrait)
images from drawable-land folder are not taken
the size of the image should be bigger on some devices
In which resolution should I provide the images? The image should have one third of the width of the display width. How can I manage that?
I tried to use this table as reference and calculating the width by taking one third of portrait size. E.g for HDPI, one third of 480 is 144, but the tablet has a width of 800 (not 480). As consequence the image is too small.
Furthermore I don't think that 9-patch files could help me here. It only describes the enlargement, but then the lowest common denominator would be an image of size LDPI ... Enlargement doesn't work so good for a text logo (custom font).
What are my options?
Edit:
starting app in landscape on smart phone leads to a black splash screen (on tablet it stays in portrait):
Adding a break point and the splash screen is shown instead of a black screen. Building an apk and installing on the smartphones works. Debug mode not.
images from drawable-land folder are not taken
Added ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation) and now they are.
But I still have no clue how to define an image, which does take a certain amount on the screen with this approach. For now I supplied a bigger image (xhdpi into hdpi) ...

you should put those images in mipmap folder not at drawable. You have to crop image into three size hpdi,ldpi and mdpi. These theree are best for any android devices.(Fits for all). If you want to display image in full screen then you can define android:background="#mipmap/image" instead of android:windowBackground="#mipmap/image" . For preventing splahscreen from being landscape you can define screen orientation inside activity like below:
<activity android:name=".Splash_Screen"
android:screenOrientation="portrait">
If you doesn't know the required resolution for image ldi,hdpi and mdpi then there's question asked on stackoverflow, google it!! Hope it helped and sorry for poor english!!

Related

What is the full screen image sizes for an Android app? (Android Studio)

I have a background image in an activity, its size was set to 1280x920, as adviced in Background image crashes android. This works perfectly.
I also have a full screen activity (sticky immersive), with the same configuration, the image is "stretched" out vertically. What should be the size of the image so that there is no scaling or stretching at all? (While the image occupies the full screen, off course)
It depends on screen. Android supports multiple screens. That's way in project we have x-hdpi, hdpi, xx-hdpi folder. As source:
https://developer.android.com/guide/practices/screens_support.html
https://developer.android.com/training/multiscreen/screensizes.html
There is no one size. Every Android device has different screen sizes. What you need to do instead is provide multiple sizes and accept some stretching or shrinking on odd sized devices. See https://developer.android.com/guide/practices/screens_support.html for more advice.

Android Splash Screen sizes (in px, to fit all devices) [duplicate]

This question already has answers here:
Android splash screen image sizes to fit all devices
(11 answers)
Closed 9 years ago.
I'm not new to Android app development. I have already created few apps with very simple UI where I didn't have to worry about screen resolution / dpi / dp... But today I have to create a more advanced Android app with a custom UI design (very "graphic").
I want to implement a splash screen (with an image in full screen). It's difficult and tedious because with Android we have to deal with a lot of resolutions and densities.
My problem
I have no idea what size to put in every drawable folder (ldpi, mdpi, hdpi and xhdpi).
What sizes (in pixels) should i create so the splash displays nice on all screens? Concretely, what files I need to create?
Few remarks
I know there are many other topics on StackOverflow (here, here or here) about Android splash screen / resolution issues. But none of these, in my opinion, gives a understandable / clear answer (I mean, with px).
I have read "Supporting Multiple Screens"
I'm aware of ratio between the densities:
ldpi (0.75x)
mdpi (baseline)
hdpi (1.5x)
xhdpi (2.0x)
xxhdpi (2.5x)
I'm aware of the 9-path image solution but it's not applicable for what I want (a full screen picture).
Tool like this one is helpful to converting dp in px
I have decompressed many APK files to see how these applications deals with splash screen images. None use the same size, it's confusing!
I do not need landscape splash screen.
With a 800x1280px PNG file (in xhdpi) it OK on my Nexus 4 emulator but verticaly stretched on Galaxy S4 emulator.
Like you already pointed out, the case you want to use as your reference frame is mdpi device. You need to make sure that you're happy with how your splash screen looks on mdpi device, and the Android will automatically re-scale your drawables for you, as long as you use .9.png (9-patch image) format and that the device has same aspect ratio.
For more information on 9-patch format, click here.
There is no single aspect for android screen, so there is no perfect solution for showing splash screen. You just need to put your image into some layout and display it as separate activity. Take a look for ImageView and scale property:
http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
There is no universal solution for all cases, but try something like that:
put RelativeLayout as base layout, set match_parent for both height and width
put ImageView at center of it, set match_parent for width, wrap_content for height, try scale mode for getting satisfying result.
You can set background drawable for the base layout to fill up margins with some plain color or gradient.
Once you get the correct scalling try how it looks on smaller screens supply other resolutions to avoid excessive downsampling.

How to properly implement full-screen images perfectly stretching on all screens?

When implementing a splash image which has such a design that image cannot be skewed or cropped if the device screen is of different resolution or size, how to perfectly implement this? Image must be a real full-screen without black background due to different aspect ration.
Shall we create splash image for every device screen size? This is how we do at the moment and it's pretty much work. So we go to Android developer support screen advise page to know what images sizes we need. you see, there are a lot of them.
Is there a better and quicker solution?
just get the splash screen in 1920*1080 and put in xxhdpi android system will auto ajust it
Stretch occurs when when try to fit an image into an image view of different Aspect-Ratio.
Create 2 or 3 images for major Aspect-Ratio and then use android:scaleType="fitXY" on your image view, for devices that uses different aspect-ratio than you specify it won't differ a lot so you don't get a noticeable stretch.
Most common aspect-ratio are:
2:1 // ultra wide ex. 800*400 screen
16:9 // HD wide ex. 1920*1080 , 1208*720 , 720*450
16:10 // wide
4:3 // old tv square-like
If you can prepare a image resolution 1920*1280 and put in drawable-xxhdpi, it would fit to any screen
Try to create a 9-patch image and use it as a background of the splash activity/view/whatever. Put your fixed size logo (or whatever you want to display) in the non-scalable part of the 9-patch and let the other areas stretch to fill the view. Note that the non-scalable area (e.g. your logo) should have size that will fit the smallest display you want to support.

Setting correct resolution for Background image

I want to set a background image into my app. I tried to set my background image in my xml file with android:background(im using a relative layout) but it seems the image was scaled and doesn't appear to be correct or in its original form.
Let's take an example if I want to display it on a 480x800 screen and only on portrait mode. Should I also produce a background image with a resolution of 480x800?
Thanks
Yes you should. Keep in mind that there are three different directories to put your drawables in (ldpi, mdpi and hdpi drawables directories) put your background images in the appropriate directory according to pixel density and the app will chose the appropriate one to use according to the device it is run on.

Android mdpi drawables for use on both Droid phone and Xoom?

I have an app developed for a Droid (phone). In the app, I use:
Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.bg);
To set the background bitmap in the application. The bitmap is sized 480x800
which is the WVGA screen size of the Droid (without status or title bar).
Two questions:
When I rotate the phone, the Droid goes into landscape mode and the background no longer fits correctly. How do I tell the App it needs to use landscape mode when I'm not using a layout?
Second, when I run this app on the Xoom, it picks the mdpi drawable which is nowhere near the size of the Xoom screen. How do I define a second mdpi drawable that has a 1280x800 size? I think if I were using layouts, I would create a layout-xlarge directory and place a 1280x800 background in the imageview of that layout, correct?
Thanks!
Update *:
Thanks for the great answers! I upvoted everyone.
I updated the code to use drawable-xlarge-port/drawable-xlarge-land for the Xoom and drawable-port-mdpi/drawable-land-mdpi for the Droid.
I'm not using layouts as I needed to draw directly onto the activity canvas and not sure how to use setContentView() from within the class where I extend View and hook into onDraw() in order to do the animation (would need to be a separate posting).
If I can figure out how to rotate the image myself I could indeed do away with the drawable-*-land and *-port directories.
You can target drawables, not just layouts. You want drawable-hdpi-large-long-land for the first situation (assuming you're letting the system handle rotation events and recreate your activity), and drawable-mdpi-xlarge for the second.
Of course it's futile to try to ship with a separate image for every conceivable phone resolution; partially because there's a lot you'd need, and partially because some targets aren't differentiable (the 854x480 and 800x480 phones out there are all hdpi-large-long, for example, despite the 54px difference). Try to use a scaleable image, a stretchable 9patch, or an image you can just fix at the top-right corner (you can define stretch behaviors using an XML-defined bitmapdrawable).
When I rotate the phone, the Droid
goes into landscape mode and the
background no longer fits correctly.
How do I tell the App it needs to use
landscape mode when I'm not using a
layout?
If you alreay detect the rotation, then the Device class is the way to go.
Second, when I run this app on the
Xoom, it picks the mdpi drawable which
is nowhere near the size of the Xoom
screen. How do I define a second mdpi
drawable that has a 1200x800 size?
You can use various image folders dependending on the resolution of the device: ldpi, mdpi, hdpi or xhdpi. You should take a look at the following page for proper support of various resolutions and screen sizes.
That's just about right. You can mix in portrait, landscape, and other modifiers, too. Don't forget to use them with your drawables as well as your layouts (and any other resource directory, for that matter). If it's the same layout and different drawables, then you only need to apply it to the drawable, for instance.
You'll want to look at the documentation for resource directories and make use of the size and orientation directory modifiers.
For example:
drawable-land-mdpi
drawable-xlarge-land
layout-port-mdpi
and such
For more information, see:
http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources
http://developer.android.com/guide/practices/screens_support.html#qualifiers

Categories

Resources