控制Android主题背景的纵横比

9

我已经按照一些建议设置了应用程序的加载屏幕(启动画面),这些建议解释了“正确的方法”:

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

当我设计启动画面的矢量图时,我将其宽高比设置为与我的手机相同(16:9),看起来很好用,但我担心在运行时在屏幕比例不同的设备上会发生什么。
为了消除它“拉伸以适应”错误大小的屏幕的可能性,我更喜欢它被居中裁剪,但由于它不是ImageView,甚至不是布局文件的一部分,我不知道任何设置中心裁剪属性的方法。
有什么建议吗?
1个回答

2

这绝对是最好/最接近的答案。我不确定这种方法是否适用于我的特定情况,但感谢您提供了更多正确方向上的信息。 - Nerdy Bunz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接