2016-05-11 7 views
3

enter image description here(曲線パスを)翻訳+スケールアニメーションAndroidの

私はそれを翻訳して、それを拡大縮小しながら、カーブでImageViewのを翻訳したいです。

アイブ氏は、私は、変数

もそのアンドロイド5はinterpolars https://stackoverflow.com/a/26591870/3518278 で基本的な曲線を提供することをここで述べ が、彼らが持っているように見える私のパスを計算する方法を見つけ出すカント https://stackoverflow.com/a/30254927/3518278 よう 複数の投稿を経て無効。

私の現在のコードは

View view; 
     ValueAnimator animator = ValueAnimator.ofFloat(0, 1); // values from 0 to 1 
     animator.setDuration(5000); // 5 seconds duration from 0 to 1 
     animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() 
     { 
      @Override 
      public void onAnimationUpdate(ValueAnimator animation) { 
       float value = ((Float) (animation.getAnimatedValue())) 
         .floatValue(); 
       // Set translation of your view here. Position can be calculated 
       // out of value. This code should move the view in a half circle. 
       img_fullscreen_drone.setTranslationX((float)(150.0 * Math.sin(value*Math.PI))); 
       img_fullscreen_drone.setTranslationY((float)(150.0 * Math.cos(value*Math.PI))); 
       img_fullscreen_drone.setScaleType(ImageView.ScaleType.CENTER); 
       img_fullscreen_drone.animate().scaleX(0.5f).scaleY(0.5f).setDuration(5000).start(); 

      } 
     }); 

     animator.start(); 

が、これはアークで私の見解を変換しますが、翻訳が完了規模が開始された後、私は規模をしたいとtoghether発生する曲線に沿って平行移動です。

すべてのヘルプはアドバンス

答えて

4

元のコードでは、画像を翻訳したアニメーションのフレームごとにスケールアニメーションが再開されていました。以下のように、スケールブロックのアニメーションコードを更新ブロックから移動するだけで済みます。

2つのわずかに異なるアニメーション方法を使用して、縮尺と翻訳の違いを確認してください。おそらく混乱します。

View view; 
    ValueAnimator animator = ValueAnimator.ofFloat(0, 1); // values from 0 to 1 
    animator.setDuration(5000); // 5 seconds duration from 0 to 1 
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() 
    { 
     @Override 
     public void onAnimationUpdate(ValueAnimator animation) { 
      float value = ((Float) (animation.getAnimatedValue())) 
        .floatValue(); 
      // Set translation of your view here. Position can be calculated 
      // out of value. This code should move the view in a half circle. 
      img_fullscreen_drone.setTranslationX((float)(150.0 * Math.sin(value*Math.PI))); 
      img_fullscreen_drone.setTranslationY((float)(150.0 * Math.cos(value*Math.PI))); 
     } 
    }); 

    animator.start(); 

    img_fullscreen_drone.setScaleType(ImageView.ScaleType.CENTER); 
    img_fullscreen_drone.animate().scaleX(0.5f).scaleY(0.5f).setDuration(5000).start(); 
+0

なぜ150.0 ?????? – kemdo

+0

150は元のポスターで使用されていた任意の値でした。 –

-1

おかげで最初のセットアニメーターを作るappreicatedされます。それでは、あなたが翻訳し、あなたが使用

のように行うために翻訳することができアニメーターの形で規模であるあなたの2つのアニメーションを分離する必要が

AnimatorSet set = new AnimatorSet(); 

のようなもの:あなた

ObjectAnimator translateAnimator = ObjectAnimator.ofInt(view, "y", toValue); 

同じあなたはスケールのために行うことができます。次に一緒に遊ぶことができます

set.playTogether(translateAnimator, scaleAnimator); 

これは一緒に拡大縮小して翻訳する必要があります。

1

ジョエルの答えをいじった後、私はあなたにもViewPropertyAnimatorを使用して、このよう一度にすべてを書くことができ判明:

img_fullscreen_drone.setScaleType(ImageView.ScaleType.CENTER); 
img_fullscreen_drone.animate() 
    .setUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 
    @Override 
    public void onAnimationUpdate(ValueAnimator animation) { 
     float value = ((Float) (animation.getAnimatedValue())); 
     // Set translation of your view here. Position can be calculated 
     // out of value. This code should move the view in a half circle. 
     img_fullscreen_drone.setTranslationX((float)(150.0 * Math.sin(value*Math.PI))); 
     img_fullscreen_drone.setTranslationY((float)(150.0 * Math.cos(value*Math.PI))); 
    }}) 
    .scaleX(0f).scaleY(0f) 
    .setDuration(5000) 
    .start(); 

私はそれがうまく動作するはずだと思うによってテストされていません。

関連する問題