【问题标题】:An integer value in xml resource file depending on DPI on Androidxml资源文件中的整数值取决于Android上的DPI
【发布时间】:2021-12-28 11:59:41
【问题描述】:

我之前关于resizing my vector splash screen image 的问题得到了很好的回答,但我想知道是否可以不使用 Java/Kotlin 代码,原因有两个:1)我是 Android 新手,不知道在哪里添加代码,2) 我不确定代码是否不会减慢启动画面的加载速度。

我的想法是我可能会添加一个整数值,如here 所述,但根据 DPI(或屏幕尺寸)使其不同,这可能吗?

然后我可能会从我的初始屏幕将其称为@myval

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle" >
            <!-- <solid android:color="#FF07862c"/> -->
            <gradient
                android:type="radial"
                android:startColor="#086824"
                android:endColor="#098a2f"
                android:gradientRadius="@myval"
                android:centerX="0.5"
                android:centerY="0.5"/>
        </shape>
    </item>
    <!-- <item android:drawable="@drawable/background0" android:gravity="center"/> -->
    <item android:drawable="@drawable/logo"
        android:width="@myval"
        android:height="@myval"
        android:gravity="center"/>
</layer-list>

【问题讨论】:

    标签: android


    【解决方案1】:

    为此,您可以使用dimenalternative resources

    文件结构:

    res/
        values/
            dimens.xml
        values-sw600dp/
            dimens.xml
    

    在每个dimens.xml 中(XX 或YY 可能在values/dimensvalues-sw600dp/dimens 之间变化):

    <resources>
        <dimen name="logoWidth">XXdp</dimen>
        <dimen name="logoHeight">YYdp</dimen>
    </resources>
    

    在layout.xml中的使用:

    <item android:drawable="@drawable/logo"
            android:width="@dimen/logoWidth"
            android:height="@dimen/logoHeight"
            android:gravity="center"/>
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-05
    • 2011-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多