我创建具有占据屏幕的顶部1/3的MapFragment和占据屏幕的底部三分之二一个ListView的图。 ListView控件有一个“处理”的正上方,用户可以用它来拖动整个ListView的向上或向下的列表项。 一旦用户发布他们的手指离开屏幕的ListView应该动画的衣柜顶部或底部边框整个屏幕。 我有它至今工作,但动画并不顺利。 有一个明显的停顿,用户从屏幕上移开手指后,ListView控件开始朝着最接近边缘动画之前。 我使用的是nineoldandroids实施ObjectAnimator,使得动画在蜂窝前的设备。 有任何想法吗?
这里是我下面的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;
}