Aspect ratio theme template (Android)

I set up a boot screen (splash) for my application, following the tips that explain the “right way”:

styles.xml:

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar"> <item name="android:windowBackground">@drawable/splash_vector_drawable</item> </style> 

manifest:

 <activity android:name="com.tba.versionc.SplashActivity" android:theme="@style/SplashTheme"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> 

Java:

 public class SplashActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = new Intent(this, MainActivity.class); startActivity(intent); finish(); } } 

When I developed a vector that can be used for the splash screen, I set its aspect ratio to match my phone (16: 9), and it seems to work fine, but I’m worried about what happens when the aspect ratio starts up on devices with screen ratios that differ.

To eliminate the possibility that it will “stretch to fit” on the wrong size screen, I would prefer it to be cropped by the center, but since it is not an ImageView or even part of the layout file, I don’t know any way to set the crop attribute center.

Is anyone

+6
source share
1 answer

See this guide by Malcolm Hollingsworth.

Basically, you need to change your image in a certain way so that Android can find out how you want it to change the image when the aspect ratio does not match the device.

Another resource here

Hope this helps!

+1
source

All Articles