画面の上 1/3 を占める MapFragment と、画面の下 2/3 を占める ListView を持つビューを作成しました。ListView には、ユーザーが ListView 全体を上下にドラッグするために使用できるリスト項目のすぐ上に「ハンドル」があります。ユーザーが画面から指を離すと、ListView は画面全体のクローゼットの上または下の境界線にアニメーション化されます。これまでのところ動作していますが、アニメーションはスムーズではありません。ユーザーが画面から指を離した後、ListView が最も近い端に向かってアニメーションを開始する前に、顕著な一時停止があります。アニメーションがハニカム以前のデバイスで動作するように、ObjectAnimator の nineoldandroids 実装を使用しています。何か案は?
以下は私の onTouch impl です。
public boolean onTouch(View v, MotionEvent event) {
final LayoutParams listLp = (LayoutParams) mListFrame.getLayoutParams();
final int topMargin = -mHandleShadow.getHeight();
final int middleMargin = getResources().getDimensionPixelSize(R.dimen.map_handle_margin_top);
final int bottomMargin = getView().getHeight() - mHandle.getHeight() - mHandleShadow.getHeight();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mInitY = (int) event.getRawY();
mTopMargin = listLp.topMargin;
break;
case MotionEvent.ACTION_MOVE:
int y = mTopMargin + (int) event.getRawY() - mInitY;
if (y >= -mHandleShadow.getHeight() && y <= (mViewHeight - mHandle.getHeight() - mHandleShadow.getHeight())) {
listLp.topMargin = y;
mListFrame.setLayoutParams(listLp);
}
break;
case MotionEvent.ACTION_UP:
if ((mInitY > event.getRawY() && mClosestAnchor == Anchor.MIDDLE) || (listLp.topMargin < middleMargin && mClosestAnchor == Anchor.BOTTOM)) {
ObjectAnimator animator = ObjectAnimator.ofInt(AnimatorProxy.wrap(mListFrame), "topMargin", topMargin);
animator.setInterpolator(new AccelerateInterpolator());
animator.start();
mClosestAnchor = Anchor.TOP;
}
else if ((mInitY < event.getRawY() && mClosestAnchor == Anchor.MIDDLE) || (listLp.topMargin > middleMargin && mClosestAnchor == Anchor.TOP)) {
ObjectAnimator animator = ObjectAnimator.ofInt(AnimatorProxy.wrap(mListFrame), "topMargin", bottomMargin);
animator.setInterpolator(new AccelerateInterpolator());
animator.start();
mClosestAnchor = Anchor.BOTTOM;
}
else {
ObjectAnimator animator = ObjectAnimator.ofInt(AnimatorProxy.wrap(mListFrame), "topMargin", middleMargin);
animator.setInterpolator(new AccelerateInterpolator());
animator.start();
mClosestAnchor = Anchor.MIDDLE;
}
break;
}
return true;
}