12

いくつかのテキストビューを取得しました。MSNのバズ効果を作成したいと思います。

私の計画は:

  • ビューを取り、左に10dipとしましょう。
  • 開始位置に戻します
  • その後、10ディップアップします
  • その後戻る
  • ダウンバック
  • 左...など。

私のポイントは、あるビューに設定したい一連の動きがあり、それを次々に実行する必要があるということです。

どうやってやるの?

4

3 に答える 3

30

あなたはおそらくAnimatorSetAnimationSetではない)を意味します。ドキュメントに書かれているように:

このクラスは、指定された順序Animatorでオブジェクトのセットを再生します。アニメーションは、一緒に、順番に、または指定された遅延後に再生するように設定できます。

AnimatorSetにアニメーションを追加するには、2つの異なるアプローチがあります。orplayTogether()メソッドplaySequentially()を呼び出してアニメーションのセットを一度に追加するかplay(Animator)、クラスのメソッドと組み合わせて使用​​してBuilderアニメーションを1つずつ追加することができます。

のために移動viewし、その後消えるアニメーション:-100px700ms300ms

final View view = findViewById(R.id.my_view);

final Animator translationAnimator = ObjectAnimator
        .ofFloat(view, View.TRANSLATION_Y, 0f, -100f)
        .setDuration(700);

final Animator alphaAnimator = ObjectAnimator
        .ofFloat(view, View.ALPHA, 1f, 0f)
        .setDuration(300);

final AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playSequentially(
        translationAnimator,
        alphaAnimator
);
animatorSet.start()
于 2016-01-12T17:42:16.160 に答える
0

複雑なアニメーションチェーンを構築するために使用できるSDK15互換クラスの始まりがあり、誰かに役立つことを願っています。デザインパターンに従って、独自のメソッドを追加できるはずです。もしそうなら、ここにコメントしてください。答えを更新します、乾杯!

package com.stuartclark45.magicmatt.util;

import java.util.LinkedList;
import java.util.List;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.view.View;

    /**
     * Used to build complex animations for a view. Example usage bellow makes view move out to the
     * right whilst rotating 45 degrees, then move out to the left.
     *
     * {@code
     *  int rotateDuration = 200;
     *  int rotation = 45;
     *  new AnimationBuilder(view)
     *    .translationX(100, rotateDuration)
     *    .rotateTo(rotation, rotateDuration)
     *    .then()
     *    .translationX(-200, rotateDuration)
     *    .start();
     * }
     *
     * @author Stuart Clark
     */

    public class AnimationBuilder {

      private View view;
      private List<Animator> setsList;
      private List<Animator> buildingList;

      public AnimationBuilder(View view) {
        this.view = view;
        this.setsList = new LinkedList<>();
        this.buildingList = new LinkedList<>();
      }

      public AnimationBuilder rotateTo(float deg, long duration) {
        buildingList.add(ObjectAnimator.ofFloat(view, "rotation", deg).setDuration(duration));
        return this;
      }

      public AnimationBuilder translationX(int deltaX, long duration) {
        buildingList.add(ObjectAnimator.ofFloat(view, "translationX", deltaX).setDuration(duration));
        return this;
      }

      public AnimationBuilder translationY(int deltaX, long duration) {
        buildingList.add(ObjectAnimator.ofFloat(view, "translationY", deltaX).setDuration(duration));
        return this;
      }

      public AnimationBuilder then() {
        createAniSet();
        // Reset the building list
        buildingList = new LinkedList<>();
        return this;
      }

      public void start() {
        createAniSet();
        AnimatorSet metaSet = new AnimatorSet();
        metaSet.playSequentially(setsList);
        metaSet.start();
      }

      private void createAniSet() {
        AnimatorSet aniSet = new AnimatorSet();
        aniSet.playTogether(buildingList);
        setsList.add(aniSet);
      }


    }
于 2017-09-27T19:35:58.900 に答える
-2

AnimationSetを使用する:

AnimationSet set = new AnimationSet(true);

Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(100);
set.addAnimation(animation);

animation = new TranslateAnimation(
    Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
    Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f
);
animation.setDuration(500);
set.addAnimation(animation);

view.startAnimation( set );
于 2011-06-07T15:29:13.920 に答える