Android XML动画可怕地落后于更大的图像

时间:2015-12-25 07:58:12

标签: android animation

我遇到了一个问题,我根本没有答案谷歌。所以我得到的图像是740x610像素,282.73kb,32位色。我只是在这个图像上应用最简单的旋转动画,这就是老板想要的。动画的xml代码是下一个。

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator">
    <rotate
        android:duration="5000"
        android:fromDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:repeatCount="infinite"
        android:toDegrees="360" />
</set>

这就是我在代码中应用动画的方式。(要动画的目标是ImageView)

levelUpLightingRight.startAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.rotate_right));

无论如何,每当动画开始旋转时,它可能是最糟糕的方式。我试图使图像更小,而BOOM,这是有效的,动画永远不会更顺畅。问题是下一个问题。我不能没有办法调整图像大小,因为如果我这样做,图像会围绕它变得粗糙并且它很难看,所以设计师让它看起来正确,所以我坚持使用这个图像大小。应用于此图像的动画滞后。我不能让图像变得更小,因为那个老板不希望看到用户界面,所以我陷入了动画纯粹落后于我以前在我的开发经验中从未见过的地步。到目前为止我尝试了什么。

1 - 将所需参数应用于manifest.xml,例如...... android:hardwareAccelerated="true"android:largeHeap="true" 2 - 尝试使用不同类型的动画,例如ValueAnimatiorObjectAnimatorAnimatorSet等。 3 - 使用第三部分库,如2d渲染。 当然没有什么能帮助我。我想在表面视图中应用动画,但我不认为它会成功。无论如何,如果有人遇到这样的问题并且有解决方案,请分享,或者至少指导正确的方向谢谢你。

完整课程代码。

package com.vegasslots.dialogs;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.vegasslots.R;

/**
 * Created by vladimirarevhstayna on 12/24/15.
 */
public class LevelUpDialog extends DialogFragment implements View.OnClickListener {
    private static final String TAG = "_LevelUpDialog";
    private ImageView coin_1;
    private ImageView coin_2;
    private ImageView coin_3;
    private ImageView coin_4;
    private ImageView coin_5;
    private ImageView coin_6;
    private ImageView coin_7;
    private ImageView coin_8;
    private ImageView coin_9;
    private ImageView coin_10;
    private ImageView coin_11;
    private ImageView coin_12;
    private ImageView coin_13;
    private ImageView coin_14;
    private ImageView coin_15;

    private CountDownTimer levelUpCountDownTimer;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        //init our viewHolder of .
        return inflater.inflate(R.layout.dialog_level_up_view, container);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        final RelativeLayout levelUpLightingLeft = (RelativeLayout) view.findViewById(R.id.levelUpLighting_left);
        RelativeLayout levelUpLightingRight = (RelativeLayout) view.findViewById(R.id.levelUpLighting_right);
        coin_1 = (ImageView) view.findViewById(R.id.imageView8);
        coin_2 = (ImageView) view.findViewById(R.id.imageView16);
        coin_3 = (ImageView) view.findViewById(R.id.imageView7);
        coin_4 = (ImageView) view.findViewById(R.id.imageView12);
        coin_5 = (ImageView) view.findViewById(R.id.imageView10);
        coin_6 = (ImageView) view.findViewById(R.id.imageView9);
        coin_6 = (ImageView) view.findViewById(R.id.imageView9);
        coin_7 = (ImageView) view.findViewById(R.id.imageView4);
        coin_8 = (ImageView) view.findViewById(R.id.imageView15);
        coin_9 = (ImageView) view.findViewById(R.id.imageView14);
        coin_10 = (ImageView) view.findViewById(R.id.imageView5);
        coin_11 = (ImageView) view.findViewById(R.id.imageView3);
        coin_12 = (ImageView) view.findViewById(R.id.imageView5);
        coin_13 = (ImageView) view.findViewById(R.id.imageView11);
        coin_14 = (ImageView) view.findViewById(R.id.imageView6);
        coin_15 = (ImageView) view.findViewById(R.id.imageView13);

        view.findViewById(R.id.mainLayout).setOnClickListener(this);
//
        levelUpLightingLeft.startAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.rotate_left));
        levelUpLightingRight.startAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.rotate_right));



        AnimatorSet set = new AnimatorSet();
        set.playTogether(

                ObjectAnimator.ofFloat(coin_1, "translationX", 180, -90),
                ObjectAnimator.ofFloat(coin_1, "translationY", 180, -90)
        );

        set.setDuration(200).start();

        levelUpCountDownTimer = new CountDownTimer(4000, 4000) {
            @Override
            public void onTick(long millisUntilFinished) {

            }

            @Override
            public void onFinish() {
                Log.d(TAG, "ON FINISH");
                if (isVisible()) {
                    dismiss();
                }
            }
        }.start();

        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

//        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#aa000000")));
//        getDialog().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        levelUpCountDownTimer.cancel();
    }

    @Override
    public void onClick(View v) {
        dismiss();
    }


}

1 个答案:

答案 0 :(得分:0)

我将动画持续时间减少到一半,并且由于某些原因它起作用了!

android:duration="500"