简体   繁体   English

使Android动画流畅

[英]Make android animation SMOOTH

I'm making a splash activity with some animations. 我正在用一些动画进行飞溅活动。

A background image(640x425, 58.4KB, JPG) is being slightly zoomed during 1500ms, 在1500毫秒内将背景图片(640x425,58.4KB,JPG)稍微缩放,

and another image(300x300, 20.3KB, PNG), is fading in during 750ms after waiting 750ms. 而另一张图片(300x300,20.3KB,PNG)在等待750毫秒后的750毫秒内逐渐消失。

The first time you run, the animation is smooth. 第一次运行时,动画很流畅。

But, If you repeat the execution, the animation is laggy. 但是,如果重复执行,动画将变得迟钝。

My phone is Samsung GALAXY Note 5. 我的手机是三星GALAXY Note 5。

Here is my code. 这是我的代码。

AndroidMenifest.xml AndroidMenifest.xml

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

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<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/AppTheme">

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

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

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
    </activity>
</application>
</manifest>

SplashAcivity.java SplashAcivity.java

import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.ViewPropertyAnimator;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class SplashActivity extends AppCompatActivity {
    private final String TAG = SplashActivity.class.getSimpleName();

    private Animation zoom_in;
    private Animation fade_in;

    private ImageView splashBackground;
    private ImageView CI;


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

        zoom_in = AnimationUtils.loadAnimation(this, R.anim.zoom_in);
        fade_in = AnimationUtils.loadAnimation(this, R.anim.fade_in);

        splashBackground = (ImageView) findViewById(R.id.splashBackground);
        CI = (ImageView) findViewById(R.id.CI);

    }

    @Override
    protected void onStart() {
        super.onStart();

        splashBackground.startAnimation(zoom_in);
        CI.startAnimation(fade_in);
    }
}

fade_in.xml fade_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true">
    <alpha
        android:startOffset="750"
        android:duration="750"
        android:fromAlpha="0"
        android:toAlpha="1"/>
</set>

zoom_in.xml zoom_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true">
    <scale
        android:duration="@integer/splash_animation_duration"
        android:pivotX="50%"
        android:pivotY="50%"
        android:fromXScale="1"
        android:fromYScale="1"
        android:toXScale="1.05"
        android:toYScale="1.05" />
</set>

使您的持续时间小于750。只需使其为300。

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

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