控制主题背景的纵横比(Android)

Control Aspect Ratio of Theme Background (Android)

我已经按照一些解释 "proper way" 的建议为我的应用程序设置了加载屏幕(启动画面):

styles.xml:

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

清单:

<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();
    }
}

当我为启动画面设计矢量可绘制对象时,我将其纵横比设置为与我的 phone (16:9) 匹配,它似乎工作正常,但我担心会发生什么在屏幕比例不同的设备上 运行 时的宽高比。

为了消除 "stretch to fit" 屏幕尺寸错误的可能性,我希望它是居中裁剪的,但由于它不是 ImageView,甚至不是布局文件的一部分,我不不知道如何设置中心裁剪属性。

有人吗?

请参阅 Malcolm Hollingsworth 的 this 指南。

基本上,您必须以特定方式修改图像,以便 Android 可以知道当宽高比与设备的宽高比不匹配时您希望它如何更改图像。

另一个资源是 here

希望对您有所帮助!