I created a view that has a MapFragment that occupies the top 1/3 of the screen and a ListView that occupies the bottom 2/3 of the screen. The ListView has a "handle" directly above its list items that the user can use to drag the entire ListView up or down. Once the user releases their finger off of the screen the ListView should animate to the closet top or bottom border of the entire screen. I have it working so far but the animation is not smooth. There is a noticeable pause, after the user release their finger from the screen, before the ListView starts animating towards the closest edge. I'm using the nineoldandroids implementation of ObjectAnimator so that the animations work on pre-Honeycomb devices. Any ideas?
Here's my onTouch impl below:
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;
}