Permalink
Browse files

Keep the splashscreen image ratio instead of streatching it.

An ImageView is used to be able to use ScaleType.CENTER_CROP, which is similar to the background-size:cover CSS property
  • Loading branch information...
1 parent b42c918 commit 333a0c3ca286cd2448625a5520ee7d8751dc50a1 @steren steren committed Apr 2, 2013
Showing with 8 additions and 1 deletion.
  1. +8 −1 framework/src/org/apache/cordova/DroidGap.java
@@ -51,6 +51,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
+import android.widget.ImageView;
import android.webkit.ValueCallback;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
@@ -1031,7 +1032,13 @@ public void run() {
root.setBackgroundColor(that.getIntegerProperty("backgroundColor", Color.BLACK));
root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT, 0.0F));
- root.setBackgroundResource(that.splashscreen);
+ // We want the splashscreen to keep its ratio,
+ // for this we need to use an ImageView and not simply the background of the LinearLayout
+ ImageView splashscreenView = new ImageView(that.getActivity());
+ splashscreenView.setImageResource(that.splashscreen);
+ splashscreenView.setScaleType(ImageView.ScaleType.CENTER_CROP); // similar to the background-size:cover CSS property
+ splashscreenView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
+ root.addView(splashscreenView);
// Create and show the dialog
splashDialog = new Dialog(that, android.R.style.Theme_Translucent_NoTitleBar);

0 comments on commit 333a0c3

Please sign in to comment.