2

ObjectAnimator.ofFloat(Object target, String xPropertyName, String yPropertyName, Path path)は23ではなくAPI 21で動作するようですか? 単純再生:ここでは、アクティビティとレイアウトです。テキストビューを長押しすると、両方のレベルが機能します。しかし、単にビューをタップ:21点の作品ではなく、23Path上のObjectAnimatorがMarshmallowで動作していませんか?

public class MainActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     final View hello = findViewById(R.id.hello); 
     final Path p = new Path(); 
     p.addCircle(-200, 0, 100, Path.Direction.CW); 
     hello.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       ObjectAnimator a = ObjectAnimator.ofFloat(hello, "translationX", "translationY", p); 
       a.setDuration(1000); 
       a.start(); 
      } 
     }); 
     hello.setOnLongClickListener(new View.OnLongClickListener() { 
      @Override 
      public boolean onLongClick(View v) { 
       ObjectAnimator a = ObjectAnimator.ofFloat(hello, "scaleX", 2); 
       a.setDuration(1000); 
       a.start(); 
       return true; 
      } 
     }); 
    } 
} 

-

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="letstwinkle.com.pathtest.MainActivity"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Hello World!" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentEnd="true" 
     android:layout_marginEnd="63dp" 
     android:layout_marginTop="210dp" 
     android:id="@+id/hello" 
     android:background="#880033"/> 
</RelativeLayout> 

をこの6月に報告されたこのバグと同じであってもよいです。 https://code.google.com/p/android/issues/detail?id=212776

+0

私はAppCompatActivityとエミュレータのバージョン22と23でテスト:22の作品は、23日に移動し始めるが、その直後にフリーズ。 – 0X0nosugar

+1

私は更新リスナーを追加して、アニメーション化された値を見ました。API 21ではそれが区別されますが、API 23では安定していて、常に同じ「-100」です。 –

+0

そしてpath.lineTo(200,200) - これは完全に動作しています。サークルのものにダイビングする必要があるか、またはテキストビューのものに変更が加えられました。 –

答えて

2

回避策として、にカスタムAnimatorUpdateListenerを使用することができます。

まず、PathにはPathMeasureが必要です。これにより、特定の距離(0 < =距離< =パス長)のパス上のパスと座標のようなデータにアクセスできます。

Path p = new Path(); 
p.addCircle(-200, 0, 100, Path.Direction.CW); 
PathMeasure pathMeasure = new PathMeasure(p, true); 

は、その後、0からの経路長をアニメーション化するためにValueAnimatorを設定します。

final ValueAnimator a = ValueAnimator.ofFloat(0,pathMeasure.getLength()); 
a.setDuration(1000); 

次に、あなたが実際にViewを操作するためAnimatorUpdateListenerを追加します。私はそれを追加する方法を最初に紹介します:

MyAnimatorUpdateListener myListener = new MyAnimatorUpdateListener(hello, pathMeasure); 
a.addUpdateListener(myListener); 

はOnClickListenerに進みます。

hello.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     a.start(); 
    } 
}); 

は、私は、コードを変更すると宣言した/良くなってOnClickListenerValueAnimator外を初期化しますのでご注意くださいパフォーマンス:この方法では、私はTextViewをクリックするたびに新しく作成されないので、ガベージコレクタは忙しくなりません:)。

は最後に、AnimatorUpdateListenerコード:

class MyAnimatorUpdateListener implements ValueAnimator.AnimatorUpdateListener 
{ 
    private View view; 
    private PathMeasure pathMeasure; 
    private float[] coordinates = new float[2]; 

    public MyAnimatorUpdateListener(View view, PathMeasure pathMeasure) 
    { 
     this.view = view; 
     this.pathMeasure = pathMeasure; 
    } 

    @Override 
    public void onAnimationUpdate(ValueAnimator animation) { 
     float distance = (float) animation.getAnimatedValue(); 
     pathMeasure.getPosTan(distance, coordinates, null); 
     view.setTranslationX(coordinates[0]); 
     view.setTranslationY(coordinates[1]); 
    } 
} 
+0

有望です。私がハッキングしたのは、xとyを別々にアニメーション化することだけでしたが、加速補間器と減速器を別々にアニメーション化して、何らかの円形を作り出しました。間違いなく良いとは思わない。私はループバックし、私ができるときにこれを実装します。 – user3175580

関連する問題