繁体   English   中英

启动画面 alpha animation 不工作

[英]Splash screen alpha animation not working

所以我有一个当前有两个活动的应用程序。 一个 SplashScreenActivity 和一个 MainActivity。 两个活动之间的转换工作得很好,但问题在于 SplashScreenActivity 本身。 在其中,有一个 ImageView 应该最初是不可见的,然后淡入。但图像始终不可见。 请帮忙。 这是代码:

SplashScreenActivity:

package com.degioncloud;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;

public class SplashScreenActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splashscreen);

        ImageView logo = (ImageView) findViewById(R.id.iv_logo);

        logo.setImageAlpha(0);
        logo.animate().alpha(1f).setDuration(1200).withEndAction(new Runnable() {
            @Override
            public void run() {
                Intent i = new Intent(SplashScreenActivity.this, MainActivity.class);
                startActivity(i);
                overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
                finish();
            }
        });
    }

}

SplashScreenActivity 的 XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".SplashScreenActivity">

    <ImageView
        android:id="@+id/iv_logo"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:src="@mipmap/ic_launcher"
        android:layout_centerInParent="true" />
</RelativeLayout>

我的清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.degioncloud">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.DegionCloud">

        <activity android:name=".MainActivity" />
        <activity android:name=".SplashScreenActivity"
            android:theme="@style/SplashScreenTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

MainActivty 是空的,所以我认为不需要共享它,但如果您需要任何其他文件,请告诉我,我会发送一份副本。

您需要为 animation 调用start()才能开始:

logo.animate().alpha(1f).setDuration(1200).withEndAction(new Runnable() {
        @Override
        public void run() {
            Intent i = new Intent(SplashScreenActivity.this, MainActivity.class);
            startActivity(i);
            overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
            finish();
        }
    }).start();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM