android启动页白屏以及避免图片icon拉伸

我们在设置app启动页面的时候一般会在app启动的第一个页面的contentview设置背景图片,但是这样做的话,当你点击手机桌面的icon到显示出你contentview设置的背景,中间会有一段时间的黑屏或者白屏,解决方法就是下面代码:

<activity
                android:name=".splash.SplashActivity"
                android:screenOrientation="portrait"
                android:theme="@style/AppTheme.Launcher">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
<style name="AppTheme.Launcher">
        <item name="android:windowBackground">@drawable/bg_app</item>
    </style>

然而你会发现在许多手机,特别是刘海屏什么的,启动页面会有拉伸导致的闪烁情况,这就需要使用下面的方法完美解决:

<style name="AppTheme.Launcher">
        <item name="android:windowBackground">@drawable/page_splash</item>
    </style>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:opacity="opaque">

    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/M_bg" />
        </shape>
    </item>

    <item android:bottom="80dp">
        <bitmap android:src="@drawable/icon_splash_logo"
        android:gravity="bottom|center_horizontal"/>

    </item>

</layer-list>

注意上面设置的bottom="80dp"要和SplashActivity的 XML 文件中图片位置android:layout_marginBottom="80dp"保持一致

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:background="@color/M_bg"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="wrap_content"
        android:scaleType="centerCrop"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="80dp"
        android:src="@drawable/icon_splash_logo"
        android:layout_height="wrap_content" />
</RelativeLayout>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值