Android studio -一些插值器动画不工作

cnwbcb6i  于 2023-02-09  发布在  Android
关注(0)|答案(1)|浏览(136)

我尝试将动画应用到我的项目中,当我将插值器设置为:
alpha.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/bounce_interpolator">

    <alpha android:fromAlpha="0"
        android:toAlpha="1"
        android:duration="4000"
        />

</set>

SplashActivity.java:

package com.example.animationtesting;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;

public class SplashActivity extends AppCompatActivity {

    ImageView imageView;
    TextView textView;
    Animation alpha;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        imageView = findViewById(R.id.imageView);
        textView = findViewById(R.id.textView);

        alpha = AnimationUtils.loadAnimation(this,R.anim.alpha);
        imageView.setAnimation(alpha);
        textView.setAnimation(alpha);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent = new Intent(SplashActivity.this,MainActivity.class);
                startActivity(intent);
                finish();
            }
        },4000);

    }
}

Android清单文件:

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

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AnimationTesting"
        tools:targetApi="31">
        <activity
            android:name=".SplashActivity"
            android:exported="true"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <meta-data
                android:name="android.app.lib_name"
                android:value="" />
        </activity>
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <meta-data
                android:name="android.app.lib_name"
                android:value="" />
        </activity>
    </application>

</manifest>

当我将插值器设置为bounce_interpolator、accelerate_interpolator、expecture_overshoot_interpolator时,代码运行正常,但当我将插值器设置为其他选项(如fade_in、fade_out、slide_out_right)时,应用崩溃。我不明白为什么会发生这种情况。

qhhrdooz

qhhrdooz1#

一开始我以为你的应用程序崩溃是因为你试图把动画放在两个不同的xml对象上,但后来我用this guide复制了整个程序,对我来说,一切都正常了。
很抱歉,我能提供的唯一解决方案是该指南的URL,但如果您有任何其他问题,请随时提问!

相关问题