[英]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.