Control Aspect Ratio of Theme Background (Android)
Asked Answered
P

1

9

I have set up a loading screen (splash) for my app by following some advice that explains the "proper way" to do it:

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 designed the vector drawable for the splash screen, I set its aspect ratio to match my phone (16:9), and it seems to work fine, but I am concerned about what will happen to the aspect ratio when running on devices with screen ratios that are different.

To eliminate the chance that it will "stretch to fit" the wrong size screen, I would prefer if it was center cropped, but since it is not an ImageView, or even part of a layout file, I don't know of any way set the center crop attribute.

Anyone?

Phenanthrene answered 13/6, 2016 at 8:19 Comment(0)
P
2

See this guide by Malcolm Hollingsworth.

Basically, you have to modify your image in a specific way so that Android can know how you want it to change the image when the aspect ratio doesn't match the device's.

Another resource is here

I hope this helps!

Pardo answered 25/6, 2016 at 23:22 Comment(1)
Well this is definitely the best/closest answer. I'm not sure if this method will work in my specific case, but thanks it's definitely more info in the right direction.Phenanthrene

© 2022 - 2024 — McMap. All rights reserved.