I need to display a splash screen on my Android app, but I need to have its proportions unchanged.
The tutorial shown on the Xamarin web site (http://docs.xamarin.com/guides/android/user_interface/creating_a_splash_screen) is using a style with a background image:
<resources> <style name="Theme.Splash" parent="android:Theme"> <item name="android:windowBackground">@drawable/splash</item> <item name="android:windowNoTitle">true</item> </style> </resources>
Unfortunatly, the image proportions are modified so it looks distorted on some screen resolutions.
It looks like the image is displayed with the FitXY parameter.
I would like the image to be scaled (liek fill_parent), but with its proportions unchanged (!fitXY)
How to achieve this?
Note : I tried to use different styles according to the device density (lp, hp, etc.) but it is not enough since this way I cannot handle all screen ratios.
Posts
Background images in themes will always stretch to fit the view. Unless... You use this little hack:
splashimage.xml
Then:
themes.xml
This is grabbed from the following SO answer: http://stackoverflow.com/a/8501398/368379
CheeseBaron,
Thank you for your answer, but this is not what I need exactly.
With your code, the image is not distorted (which is cool), but is displayed at size 1:1, i.e. not scale to fit the screen.
What I need is simple, this is the default behavior of an image put in a layout, like this:
As you can see, this image is displayed with its proportion kept, but streteched to fit the screen. If the image ratio is not the same as the screen ratio, the black bands witll be dispalyed either at top/bottom of the screen, or at top/bottom of the screen.
This is what I need, but in the splash screen.
You can try play with the
Gravity
attribute. The different types you can use can be found here: https://developer.android.com/reference/android/view/Gravity.htmlSomething like
fill
orfill_horiziontal
might be what you are looking for.How do create a splash screen that fade out when the activity fades in?
@HashtagAndroid you will need to look into how
OverridePendingTransition
works.Some more info in this StackOverflow question.