RelativeLayout (さまざまな位置に、マージンを使用) でいくつかのビューを持っているアプリを作成しており、Honeycomb の新しいアニメーション API を使用してそれらをアニメーション化しています。アニメーションは繰り返されますが、繰り返しごとにしばらく待つ必要があるため、繰り返しモードを使用できません。
うまくいっているのですが、別の場所に移動してアニメーションを止めたいところがありますが、止められません。私はそれらを動かしていますが、それらは表示されず、まだアニメーション化されているため、突然通り過ぎるのが見えます. 考えられる限りの方法を試しました。助けてください。
コード:
if(!mMoving){
mMoving = true;
for(int i = 0; i < mImagesList.size(); i++){
final LinearLayout f = mImagesList.get(i);
if(mMoving){
ObjectAnimator anim = ObjectAnimator.ofFloat(f, "x", Math.round(mScreenWidth * 1.4));
mAnimators.add(anim);
anim.setDuration(mRandom.nextInt(10000) + 8000);
anim.setStartDelay((mRandom.nextInt(4000) + 3000) * (i / ITEMS_PER_SCREEN));
anim.addListener(new AnimatorListener() {
@Override
public void onAnimationEnd(Animator animation) {
if(mMoving){
mAnimators.remove(animation);
ImageView img = (ImageView)f.findViewById(R.id.stream_feed_item_pic);
int picWidth = img.getDrawable().getIntrinsicWidth();
Animator anim = ObjectAnimator.ofFloat(f, "x", -Math.round(picWidth * 1.4), Math.round(mScreenWidth * 1.2));
mAnimators.set(mAnimators.indexOf(animation), anim);
anim.setDuration(mRandom.nextInt(14000) + 8000);
anim.setStartDelay((mRandom.nextInt(6000) + 3000) * (mImagesList.size() / ITEMS_PER_SCREEN));
anim.addListener(this);
anim.start();
}
}
});
anim.start();
}
}
mMoving = true;
return true;
}
ご覧のとおり、すべての画像でリスナーを持つアニメーターを作成しています。すべてのアニメーションの終了時に、リスナーが呼び出され、新しいアニメーションが作成され、開始の遅延が発生します。すべてのアニメーションをリストに保存します。
これは、それらを停止するための私の (必死の) 試みです。
if(mMoving){
mMoving = false;
for(Animator anim : mAnimators){
anim.setStartDelay(0);
anim.setDuration(0);
anim.start();
anim.cancel();
anim.removeAllListeners();
anim.setTarget(null);
}
mAnimators.clear();
}
これは、それらを別のレイアウトに移動する方法です。
mContainer.removeAllViews();
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(picWidth, picHeight);
params.leftMargin = 0;
params.topMargin = 0;
if(size == SMALL_SIZE){
if(mSmallCounter < mSmallIdList.length){
RelativeLayout frame = (RelativeLayout)findViewById(mSmallIdList[mSmallCounter++]);
frame.addView(f, params);
}
}
私は非常に絶望的で、約100の方法を試しました!
注: これはハニカム API です。3.0 より前のアニメーションではなく、アニメーターを使用しています。