所以,我的同事已经做了很长时间的这个应用程序,我们有一种方法可以购买购物车。现在,我们现在拥有的动画只是线性下降,具有一些反弹效果。由于整个逻辑链接到侦听器和接口,为了保留它,我想将ArcTranslation归于它。现在,我的ArcTranslation.class看起来像:
import android.graphics.Point;
import android.view.animation.Animation;
import android.view.animation.Transformation;
/**
* Created by vulov on 16-May-16.\n
*/
public class ArcTranslation extends Animation {
private Point start;
private Point end;
private Point middle;
private final float mFromXValue;
private final float mToXValue;
private final float mYValue;
private final int mFromXType;
private final int mToXType;
private final int mYType;
/**
* A translation along an arc defined by three points and a Bezier Curve
*
* @param duration - the time in ms it will take for the translation to complete
* @param fromXType - One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
* @param fromXValue - Change in X coordinate to apply at the start of the animation
* @param toXType - One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
* @param toXValue - Change in X coordinate to apply at the end of the animation
* @param yType - One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
* @param yValue - Change in Y coordinate to apply at the middle of the animation (the radius of the arc)
*/
public ArcTranslation(long duration, int fromXType, float fromXValue,
int toXType, float toXValue, int yType, float yValue) {
setDuration(duration);
mFromXValue = fromXValue;
mToXValue = toXValue;
mYValue = yValue;
mFromXType = fromXType;
mToXType = toXType;
mYType = yType;
}
/**
* Calculate the position on a quadratic bezier curve given three points
* and the percentage of time passed.
* from http://en.wikipedia.org/wiki/B%C3%A9zier_curve
*
* @param interpolatedTime - the fraction of the duration that has passed where 0<=time<=1
* @param p0 - a single dimension of the starting point
* @param p1 - a single dimension of the middle point
* @param p2 - a single dimension of the ending point
*/
private long calcBezier(float interpolatedTime, float p0, float p1, float p2) {
return Math.round((Math.pow((1 - interpolatedTime), 2) * p0)
+ (2 * (1 - interpolatedTime) * interpolatedTime * p1)
+ (Math.pow(interpolatedTime, 2) * p2));
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
float dx = calcBezier(interpolatedTime, start.x, middle.x, end.x);
float dy = calcBezier(interpolatedTime, start.y, middle.y, end.y);
t.getMatrix().setTranslate(dx, dy);
}
@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
int startX = Math.round(resolveSize(mFromXType, mFromXValue, width, parentWidth));
int endX = Math.round(resolveSize(mToXType, mToXValue, width, parentWidth));
int middleY = Math.round(resolveSize(mYType, mYValue, width, parentWidth));
int middleX = startX + ((endX - startX) / 2);
start = new Point(startX, 0);
end = new Point(endX, 0);
middle = new Point(middleX, middleY);
}
}
在购物车中激活饮料的方法:
private void animateToCart(int[] location, final Drink drink) {
final TextView badge = new TextView(getActivity());
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(getResources().getDimensionPixelSize(R.dimen.MenuGridBothPaddings), getResources().getDimensionPixelSize(R.dimen
.MenuGridBothPaddings));
params.setMargins(width + (width / 2) - 10, location[1] - getResources().getDimensionPixelSize(R.dimen.ActionBarHeight), 0, 0);
badge.setLayoutParams(params);
badge.setVisibility(View.VISIBLE);
badge.setBackgroundDrawable(getResources().getDrawable(R.drawable.bottom_menu_badge));
badge.setTextColor(Color.WHITE);
badge.setText("1");
badge.setGravity(Gravity.CENTER);
badge.bringToFront();
top.addView(badge, params);
AnimatorSet animatorSet = new AnimatorSet();
animatorSetList.add(animatorSet);
CancelListener cancelListener = new CancelListener(badge, drink);
animatorSet.addListener(cancelListener);
/* animatorSet.addListener(new SimpleAnimatorListener() {
@Override
public void onAnimationEnd(Animator animator) {
super.onAnimationEnd(animator);
badge.setVisibility(View.GONE);
restoreOrdersBadgeAnimate();
if (Session.isOrderStatusSuccess()) {
Session.clearTab();
}
if (Session.getReceiverUser() != null && Session.getNumBarTabDrinks() >= 1) {
setActiveDialog(displayError(R.string.MenuOneAtATime));
return;
}
if (DrinkCategoryMetadata.isMixerDrinkCategory(drink.categoryId)) {
DrinkMeta drinkMeta = Session.addBarTabDrinkGetMeta(drink);
Dialog dialog = new MixersDialog(getActivity(), drink);
dialog.setOnDismissListener(new MixersDismissListener(drink, drinkMeta));
dialog.show();
setActiveDialog(dialog);
} else {
Session.addBarTabDrink(drink);
((BmadUserActivity) getActivity()).setBarTabNum(Session.getNumBarTabDrinks(), true);
setBarTabNum(Session.getNumBarTabDrinks());
if (ApplicationLoader.getCurrentFragment() instanceof BuyDrinksFragment) {
((BmadUserActivity) getActivity()).getBottomMenu().getBadge(BottomMenu.Item.CURRENT).setVisibility(View.VISIBLE);//change from INVISIBLE to VISIBLE
}
((BmadUserActivity) getActivity()).setTooltipBarTab(drink.name);
setTooltipBarTab(drink.name);
}
}
});*/
animatorSet.playTogether(ObjectAnimator.ofFloat(badge, "translationY", (height - location[1]) - getResources().getDimensionPixelSize(R.dimen.BottomMenuHeight) - 80));
animatorSet.setDuration(height / 2);
animatorSet.setInterpolator(new BounceInterpolator());
animatorSet.start();
}
我想在这里做的事情: - 如何将我的动画类实现到这个事件流中(进入AnimatorSet) - 由于这是一个片段内部活动,底部有标签布局,如何使视图落在所有内容的前面,所以当它到达底部时它不在标签栏后面?