Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show splash screen image with auto fit

I am using the following style to display a splash screen for an android application written in MonoDroid. However, it seems to take the image and maximize it to fit the whole screen while messing up the aspect ratio. Thus, the image looks huge and awful.

Is there a way to get it to maximize, but maintain the aspect ratio so it still looks good?

<style name="Theme.Splash" parent="android:Theme">   <item name="android:windowBackground">@drawable/splashscreenimage</item>   <item name="android:windowNoTitle">true</item> </style> 

This is the activity in C# which creates the splash screen and goes to the login.

  [Activity(MainLauncher = true, Theme = "@style/Theme.Splash", NoHistory = true)]   public class SplashScreenActivity : Activity   {     protected override void OnCreate(Bundle bundle)     {       base.OnCreate(bundle);        // Start our real activity       StartActivity(typeof(LoginActivity));     }   } 
like image 495
Telavian Avatar asked Sep 26 '12 18:09

Telavian


People also ask

How do I change the image size on splash screen?

I suggest you to use the animated splash available in pub. dev. Animated Splash I have used this plugin in my App and customized it according to my needs. In there, you can change the size of the image and it is written in dart so you can understand it easily also.

How do you create an animated splash screen?

Go to app > java > first package name > right-click > New > Activity > Empty Activity and create another activity and named it as SplashScreen. Edit the activity_splash_screen. xml file and add image, text in the splash screen as per the requirement.

What is a splash screen image?

A splash screen is a graphical control element consisting of a window containing an image, a logo, and the current version of the software. A splash screen can appear while a game or program is launching. A splash page is an introduction page on a website.


1 Answers

There are several types of drawables in Android including actual bitmaps, nine-patch, and XML files. Try wrapping your image file with an XML file that gives it attributes and then use the XML file as drawable instead of the source image.

Let's assume your xml file is called scaled_background and your original image is simply background.png:

<?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:gravity="center" android:src="@drawable/background" /> 

Instead of setting your background to reference @drawable/background you'd set it to reference the XML file: @drawable/scaled_background in this example. Details on the scaling modes are mentioned in the Drawable documentation.

like image 106
profexorgeek Avatar answered Sep 23 '22 14:09

profexorgeek