TranslateAnimationを使用して線形レイアウトを移動したいと考えました。私には2つの問題があります。私のベースSDKはAndroid 2.2です。TranslateAnimationが期待通りに動作しない
- アニメーションが終了しても、線形レイアウトのタッチ可能な領域はまったく移動しませんでした。
- アニメーションが終了した直後に数フレームの画面が点滅しました。
最初は、AnimationListenerとLinearLayout.layout()を使用しませんでした。次のコードを使用してアニメーションを完成させると、ビューの位置が実際に変更されました。しかし、タッチ可能な領域は、アニメーション中にビューと共に移動していないように見えました。その結果、アニメーション後にビューのボタンのいずれかをクリックしようとしたときに何も起こりませんでした。ボタンの元の領域(アニメーションが行われる前の元の領域)をクリックすると、on_click_listenerがトリガされました。
は、私は、コードの行を削除
tmpAnimation.setFillAfter(true);
及び(AnimationListenerとLinearLayout.layoutを試み)。それは助けをして第1の問題を曇らせた。
しかし、2つの問題が発生しました。アニメーションの後、私の線形レイアウトのいくつかは数フレームの間点滅し、次に注文に戻ります。私はmidLinearlayout.requestLayout()を試してみた
、それはwork.Iが実装Animation.AnimationListenerを試していないと誰かが言ったようにonAnimationEndオーバーライドしますが、それはどちらか動作しません。
TranslateAnimation tmpAnimation = new TranslateAnimation(midLinearlayout.getLeft(),midLinearlayout.getLeft(),midLinearlayout.getTop(),midLinearlayout.getTop()+100);
//tmpAnimation.setFillAfter(true);
tmpAnimation.setDuration(2000);
tmpAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void onAnimationEnd(Animation animation) {
Log.v("onflingTest","top="+midLinearlayout.getTop()+" left="+midLinearlayout.getLeft()+" right" + midLinearlayout.getRight());
midLinearlayout.layout(midLinearlayout.getLeft(), midLinearlayout.getTop()+100, midLinearlayout.getLeft() + midLinearlayout.getMeasuredWidth(), midLinearlayout.getTop()+ 100 + midLinearlayout.getMeasuredHeight());
}
@Override
public void onAnimationRepeat(Animation animation) {
//To change body of implemented methods use File | Settings | File Templates.
}
});
私は以下のコードでこの問題を解決しました: EditText stucks after animation and alive back on scrolling......?
ありがとうございました。しかし、私は、アニメーションの後に線形レイアウト上のボタンをクリックしたいと思います。 – peanut