ダミーのTranslateAnimationを使用していくつかのレイアウトプロパティを設定するカスタムビューを作成しました。Interpolatorを使用して高さを計算し、TranslateAnimationのapplyTransformation()メソッド内のビューに適用します。
アクティビティからアニメーションをトリガーすると、これは非常にうまく機能します。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i("test", "onCreate()");
view.expand(); // This method starts the animation
}
タッチイベントを使用して同じことを行おうとすると、何も起こりません。
@Override
// This method is touch handler of the View itself
public boolean onTouch(View v, MotionEvent event) {
Log.i("test", "onTouch()");
this.expand(); // onTouch is part of the view itself and calls expand() directly
return true;
}
私のexpandメソッドは次のようになります。
public void expand() {
Log.i("test", "Expand!");
TranslateAnimation anim = new TranslateAnimation(0, 0, 0, 0) {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
Log.i("test", "applyTransformation()");
super.applyTransformation(interpolatedTime, t);
// do something
}
};
anim.setDuration(500);
anim.setInterpolator(new AccelerateDecelerateInterpolator());
this.someInternalView.startAnimation(anim);
}
アクティビティが作成されると、Logcatは「onCreate()」を表示しますタッチイベント内は「onTouch()」を表示しますexpand()メソッド内はLogcatは「Expand!」を表示します -アクティビティまたはイベントから呼び出されます。
メソッドapplyTransformation()の内部では、Logcatは「applyTransformation()」を示しています-しかし!Expand()がonCreate()から呼び出された場合のみ。イベントからアニメーションを開始しようとして失敗しました。
これは、ある種のスレッドの問題のように私には見えます。これでいいの?足りないものはありますか?他の投稿からわかる限り、イベントからアニメーションを開始すると問題なく動作するはずです...
前もって感謝します!