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)); } }
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With