0

画面のほぼ半分から下部近くまで円が移動する簡単なアニメーションがあります。それはゆっくりと落ちます。私の意図は、クリックしたときに何かをするようにクリックできるようにすることです。開始位置から停止位置までどこでもクリックできるようにしてほしい。

円は で実装され、と属性ImageViewを追加しました。円が始まった場所を押すと、ハンドラーは期待どおりに動作しますが、アニメーション中に画像を「追跡」していないようです。clickableonClickonClick

クラスが見つかり、ハンドラーを介してアニメーションが終了したときに の座標AnimationListenerを更新できましたが、アニメーションの実行中にこれを行う方法はないようです。ImageViewonAnimationEnd()

onClickアニメーションの移動中にハンドラーの位置を更新するために使用できるクラス/メソッドはありますか? そうでない場合、目標を達成するために使用すべき別の種類のアニメーションはありますか?


関連コード:

私のImageViewのxmlレイアウト:

<ImageView
   android:id="@+id/bubble"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_centerHorizontal="true"
   android:scaleType="fitCenter"
   android:src="@drawable/bubble"
   android:clickable="true"
   android:onClick="popBubble"
   android:contentDescription="bubble"
   android:layout_below="@id/sun"
   />

onCreateアニメーションを開始するメソッドの Java ソース コード:

ImageView bubble = (ImageView) findViewById(R.id.bubble);
Animation bubblefall = AnimationUtils.loadAnimation(this, R.anim.bubble_fall);
bubblefall.setAnimationListener(new MyAnimationListener());
bubble.startAnimation(bubblefall);

私の AnimationListener を設定する Java ソース コード:

private class MyAnimationListener implements AnimationListener{

  @Override
  public void onAnimationEnd(Animation arg0) {
  ImageView local = (ImageView) findViewById(R.id.bubble);
  local.clearAnimation();
  local.offsetTopAndBottom(50);

アニメーション XML:

<set xmlns:android="http://schemas.android.com/apk/res/android"    
   android:shareInterpolator="false"    
   android:duration="10000"    
   android:fillAfter="true"    
   android:interpolator="@android:anim/linear_interpolator" >
  <translate    
    android:fromYDelta="10%p"    
    android:toYDelta="60%p"    />
  <alpha    
    android:fromAlpha="0.7"    
    android:toAlpha="0.7"    />
</set>
4

1 に答える 1

0

次を使用できますAnimatorUpdateListener

bubblefall.addUpdateListener(new AnimatorUpdateListener(){
    @Override
    public void onAnimationUpdate(ValueAnimator animation) {
        //get animated value using
        animation.getAnimatedValue();

        //then handle the click listener
    }

});
于 2013-10-20T14:59:59.717 に答える