public void backTopAndCenterWithAnimation() { mStepLayout.setVisibility(View.VISIBLE); if (Build.VERSION.SDK_INT >= 11) { float centerHeight = mActivity.getResources().getDimension(R.dimen.pg_sdk_edit_center_move_top_height); ObjectAnimator centerAnimator = ObjectAnimator.ofFloat(mCenterLayoutParent, "y", -centerHeight, 0f); centerAnimator.setDuration(ANIMATION_TIME); centerAnimator.start(); float topHeight = mActivity.getResources().getDimension(R.dimen.pg_sdk_edit_top_height); ObjectAnimator topAnimator = ObjectAnimator.ofFloat(mFirstTopView, "y", -topHeight, 0f); topAnimator.setDuration(ANIMATION_TIME); topAnimator.start(); } else { mFirstTopView.setVisibility(View.VISIBLE); float topHeight = mActivity.getResources().getDimension(R.dimen.pg_sdk_edit_top_height); float bottomHeight = mActivity.getResources().getDimension(R.dimen.pg_sdk_edit_bottom_height); mCenterLayoutParent.setPadding( mCenterLayoutParent.getPaddingLeft(), Math.round(topHeight), mCenterLayoutParent.getPaddingRight(), Math.round(bottomHeight)); } }
@Override protected void setupAnimation(View view) { getAnimatorSet() .playTogether( ObjectAnimator.ofFloat(view, "translationX", 300, 0).setDuration(mDuration), ObjectAnimator.ofFloat(view, "alpha", 0, 1).setDuration(mDuration * 3 / 2)); }
public void setPressed(boolean pressed) { if (mGlowBG != null) { if (pressed != isPressed()) { if (mPressedAnim != null && mPressedAnim.isRunning()) { mPressedAnim.cancel(); } final AnimatorSet as = mPressedAnim = new AnimatorSet(); if (pressed) { if (mGlowScale < GLOW_MAX_SCALE_FACTOR) mGlowScale = GLOW_MAX_SCALE_FACTOR; if (mGlowAlpha < mQuiescentAlpha) mGlowAlpha = mQuiescentAlpha; setDrawingAlpha(1f); as.playTogether( ObjectAnimator.ofFloat(this, "glowAlpha", 1f), ObjectAnimator.ofFloat(this, "glowScale", GLOW_MAX_SCALE_FACTOR)); as.setDuration(50); } else { mAnimateToQuiescent.cancel(); mAnimateToQuiescent = animateToQuiescent(); as.playTogether( ObjectAnimator.ofFloat(this, "glowAlpha", 0f), ObjectAnimator.ofFloat(this, "glowScale", 1f), mAnimateToQuiescent); as.setDuration(500); } as.start(); } } super.setPressed(pressed); }
private void performSwitch() { ObjectAnimator animator1 = ObjectAnimator.ofFloat( mFirstView, "translationY", mFirstView.getTranslationY() - mBannerHeight); ObjectAnimator animator2 = ObjectAnimator.ofFloat( mSecondView, "translationY", mSecondView.getTranslationY() - mBannerHeight); AnimatorSet set = new AnimatorSet(); set.playTogether(animator1, animator2); set.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mFirstView.setTranslationY(0); mSecondView.setTranslationY(0); View removedView = getChildAt(0); mPosition++; mAdapter.setItem(removedView, mAdapter.getItem(mPosition % mAdapter.getCount())); removeView(removedView); addView(removedView, 1); } }); set.setDuration(mAnimDuration); set.start(); }
private void stopAnimator() { ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(this, "scaleX", 1, 0); ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(this, "scaleY", 1, 0); scaleXAnimator.setDuration(300); scaleXAnimator.setInterpolator(new LinearInterpolator()); scaleYAnimator.setDuration(300); scaleYAnimator.setInterpolator(new LinearInterpolator()); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(scaleXAnimator, scaleYAnimator); animatorSet.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) {} @Override public void onAnimationEnd(Animator animation) { isStart = false; } @Override public void onAnimationCancel(Animator animation) {} @Override public void onAnimationRepeat(Animator animation) {} }); animatorSet.start(); }
private void startTrans() { ObjectAnimator animator = ObjectAnimator.ofFloat(this, "translationX", 0, width / 3); animator.setDuration(200); animator.setInterpolator(new DecelerateInterpolator()); ObjectAnimator animator2 = ObjectAnimator.ofFloat(this, "translationX", width / 3, -width / 4); animator2.setDuration(200); animator2.setInterpolator(new DecelerateInterpolator()); ObjectAnimator animator3 = ObjectAnimator.ofFloat(this, "translationX", -width / 4, width / 5); animator3.setDuration(200); animator3.setInterpolator(new DecelerateInterpolator()); ObjectAnimator animator4 = ObjectAnimator.ofFloat(this, "translationX", width / 5, -width / 6); animator4.setDuration(200); animator4.setInterpolator(new DecelerateInterpolator()); ObjectAnimator animator5 = ObjectAnimator.ofFloat(this, "translationX", -width / 6, 0); animator5.setDuration(200); animator5.setInterpolator(new DecelerateInterpolator()); AnimatorSet set = new AnimatorSet(); List<Animator> items = new ArrayList<Animator>(); items.add(animator); items.add(animator2); items.add(animator3); items.add(animator4); items.add(animator5); set.playSequentially(items); set.start(); }
@Override public void onTextSizeChanged(final TextView textView, float oldSize) { if (mCurrentState != CalculatorState.INPUT) { // TODO dont animate when showing graph // Only animate text changes that occur from user input. return; } // Calculate the values needed to perform the scale and translation animations, // maintaining the same apparent baseline for the displayed text. final float textScale = oldSize / textView.getTextSize(); final float translationX; if (android.os.Build.VERSION.SDK_INT >= 17) { translationX = (1.0f - textScale) * (textView.getWidth() / 2.0f - textView.getPaddingEnd()); } else { translationX = (1.0f - textScale) * (textView.getWidth() / 2.0f - textView.getPaddingRight()); } final float translationY = (1.0f - textScale) * (textView.getHeight() / 2.0f - textView.getPaddingBottom()); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether( ObjectAnimator.ofFloat(textView, View.SCALE_X, textScale, 1.0f), ObjectAnimator.ofFloat(textView, View.SCALE_Y, textScale, 1.0f), ObjectAnimator.ofFloat(textView, View.TRANSLATION_X, translationX, 0.0f), ObjectAnimator.ofFloat(textView, View.TRANSLATION_Y, translationY, 0.0f)); animatorSet.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime)); animatorSet.setInterpolator(new AccelerateDecelerateInterpolator()); animatorSet.start(); }
private void animateFadeOutFadeIn(final View src, final View dst) { if (dst.getVisibility() != View.VISIBLE || dst.getAlpha() != 1f) { AnimatorSet set = new AnimatorSet(); set.playSequentially( ObjectAnimator.ofFloat(src, "alpha", 0f), ObjectAnimator.ofFloat(dst, "alpha", 1f)); set.setInterpolator(new LinearInterpolator()); set.addListener( new AnimatorListener() { @Override public void onAnimationStart(Animator animation) { src.setAlpha(1f); dst.setAlpha(0f); src.setVisibility(View.VISIBLE); dst.setVisibility(View.VISIBLE); } @Override public void onAnimationRepeat(Animator animation) {} @Override public void onAnimationEnd(Animator animation) { src.setVisibility(View.GONE); } @Override public void onAnimationCancel(Animator animation) {} }); set.setDuration(250); set.start(); } else { src.setAlpha(1f); src.setVisibility(View.GONE); } }
private ObjectAnimator createAnimation(View view, AnimationParams params) { ObjectAnimator animator = null; if (params.attr != null) { if (params.paramsFloat != null) { animator = ObjectAnimator.ofFloat(view, params.attr, params.paramsFloat); } else if (params.paramsInt != null) { animator = ObjectAnimator.ofInt(view, params.attr, params.paramsInt); } } else { if (params.paramsFloat != null && params.propertyFloat != null) { animator = ObjectAnimator.ofFloat(view, params.propertyFloat, params.paramsFloat); } else if (params.paramsInt != null && params.propertyInt != null) { animator = ObjectAnimator.ofInt(view, params.propertyInt, params.paramsInt); } } if (animator == null) { throw new RuntimeException("Can't support this animation params"); } if (params.evaluator != null) { animator.setEvaluator(params.evaluator); } if (params.interpolator != null) { animator.setInterpolator(params.interpolator); } return animator; }
private void init() { FrameLayout frameLayout = (FrameLayout) findViewById(R.id.framelayout_activity_detail2); ObjectAnimator.ofFloat(frameLayout,"scaleX",0.6f,1.0f).setDuration(2000).start(); ObjectAnimator.ofFloat(frameLayout,"scaleY",0.4f,1.0f).setDuration(2000).start(); // toolbar相关 toolbar = (Toolbar) findViewById(R.id.layout_detail_toolbar); titleTextView = (TextView) findViewById(R.id.title_detail_activity_scrollview); // scrollview相关 imageView = (ImageView) findViewById(R.id.image_detail); imageViewBackground = (ImageView) findViewById(R.id.background_detail); winchanceScrollView = (ObservableScrollView) findViewById(R.id.scrollview_detail); // layout相关 layoutReason = (LinearLayout) findViewById(R.id.layout_introduce); linearLayout = (LinearLayout) findViewById(R.id.show); linearLayoutShowContent = (LinearLayout) findViewById(R.id.show_content); relativeLayoutBuy = (RelativeLayout) findViewById(R.id.btn_buy); relativeLayoutRan = (RelativeLayout) findViewById(R.id.btn_rabingluan); relativeLayoutSeemore = (RelativeLayout) findViewById(R.id.see_more); // imageView.setImageResource(R.mipmap.image_second); // observer = imageView.getViewTreeObserver(); outRect = new Rect(); getWindow().getDecorView().getWindowVisibleDisplayFrame(outRect); LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = layoutInflater.inflate(R.layout.activity_detail_item, null); dealToolbar(); setOnclickListener(); }
/** 开启打开动画 */ private void startAnim() { ObjectAnimator tranAnimY = ObjectAnimator.ofFloat(mMenuViewSmall, "translationY", 0, -20); ObjectAnimator tranAnimPointX = ObjectAnimator.ofFloat(mMenuViewSmall, "translationX", 0, viewMoveX); ObjectAnimator tranAnimPointY = ObjectAnimator.ofFloat(mMenuViewSmall, "translationY", -20, viewMoveY); ObjectAnimator scaleAnimX = ObjectAnimator.ofFloat(mMenuViewSmall, "scaleX", 1.0f, (toValueX + 1.0f)); ObjectAnimator scaleAnimY = ObjectAnimator.ofFloat(mMenuViewSmall, "scaleY", 1.0f, (toValueY + 1.0f)); AnimatorSet set = new AnimatorSet(); set.setDuration(500); set.play(tranAnimY) .before(tranAnimPointX) .before(tranAnimPointY) .before(scaleAnimX) .before(scaleAnimY); scaleAnimX.addUpdateListener( new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float value = (float) animation.getAnimatedValue(); // mMenuViewSmall.setScaleX(value); mContentView.setAlpha((float) (1 - ((value - 1) / toValueX) * 0.5)); mContentView.setScaleX((float) (1 - ((value - 1) / toValueX) * 0.2)); mContentView.setScaleY((float) (1 - ((value - 1) / toValueX) * 0.2)); } }); set.addListener(this); set.start(); }
/** * 隐藏vote栏 */ private void destoryFrame() { ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(relativeLayoutBuy, "translationX", 0, -500).setDuration(500); objectAnimator.addListener(animatorListener); objectAnimator.start(); objectAnimator.ofFloat(relativeLayoutRan, "translationX", 0, -2000).setDuration(500).start(); objectAnimator.ofFloat(linearLayout, "alpha", 1.0f, 0.2f).setDuration(300).start(); }
/** * 显示vote栏 */ private void showFrame() { linearLayout.setVisibility(View.VISIBLE); ObjectAnimator.ofFloat(relativeLayoutBuy, "translationX", -500, 0).setDuration(500).start(); ObjectAnimator.ofFloat(relativeLayoutRan, "translationX", -2000, 0).setDuration(500).start(); ObjectAnimator.ofFloat(linearLayout, "alpha", 0.2f, 1.0f).setDuration(300).start(); }
private void setupAnimations() { mObjectAnimatorAngle = ObjectAnimator.ofFloat(this, mAngleProperty, 360f); mObjectAnimatorAngle.setInterpolator(ANGLE_INTERPOLATOR); mObjectAnimatorAngle.setDuration(ANGLE_ANIMATOR_DURATION); mObjectAnimatorAngle.setRepeatMode(ValueAnimator.RESTART); mObjectAnimatorAngle.setRepeatCount(ValueAnimator.INFINITE); mObjectAnimatorSweep = ObjectAnimator.ofFloat(this, mSweepProperty, 360f - MIN_SWEEP_ANGLE * 2); mObjectAnimatorSweep.setInterpolator(SWEEP_INTERPOLATOR); mObjectAnimatorSweep.setDuration(SWEEP_ANIMATOR_DURATION); mObjectAnimatorSweep.setRepeatMode(ValueAnimator.RESTART); mObjectAnimatorSweep.setRepeatCount(ValueAnimator.INFINITE); mObjectAnimatorSweep.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) {} @Override public void onAnimationEnd(Animator animation) {} @Override public void onAnimationCancel(Animator animation) {} @Override public void onAnimationRepeat(Animator animation) { toggleAppearingMode(); } }); }
public void setPressed(boolean pressed) { if (mGlowBG != null) { if (pressed != isPressed()) { if (mPressedAnim != null && mPressedAnim.isRunning()) { mPressedAnim.cancel(); } final AnimatorSet as = mPressedAnim = new AnimatorSet(); if (pressed) { if (mGlowScale < GLOW_MAX_SCALE_FACTOR) mGlowScale = GLOW_MAX_SCALE_FACTOR; if (mGlowAlpha < BUTTON_QUIESCENT_ALPHA) mGlowAlpha = BUTTON_QUIESCENT_ALPHA; setDrawingAlpha(1f); as.playTogether( ObjectAnimator.ofFloat(this, "glowAlpha", 1f), ObjectAnimator.ofFloat(this, "glowScale", GLOW_MAX_SCALE_FACTOR)); as.setDuration(50); } else { as.playTogether( ObjectAnimator.ofFloat(this, "glowAlpha", 0f), ObjectAnimator.ofFloat(this, "glowScale", 1f), ObjectAnimator.ofFloat(this, "drawingAlpha", BUTTON_QUIESCENT_ALPHA)); as.setDuration(500); } as.start(); } } super.setPressed(pressed); }
public void loadOfFloat(String key, Property<View, Float>... property) { View[] vs = getViews(key); if (vs != null) { for (int i = 0; i < motion.length; i++) { ObjectAnimator[] obs = new ObjectAnimator[property.length]; for (int j = 0; j < property.length; j++) { obs[j] = ObjectAnimator.ofFloat(vs[i], property[j], 0, 0); } animList.add(obs); } } else { View v = getSingleView(key); if (v != null) { for (int i = 0; i < motion.length; i++) { ObjectAnimator[] obs = new ObjectAnimator[property.length]; for (int j = 0; j < property.length; j++) { obs[j] = ObjectAnimator.ofFloat(v, property[j], 0, 0); } animList.add(obs); } } } playMotion(); }
public void setAnimation(View view) { animatorSet.playTogether( new Animator[] { ObjectAnimator.ofFloat(view, "scaleX", new float[] {1.0F, 1.5F}), ObjectAnimator.ofFloat(view, "scaleY", new float[] {1.0F, 1.5F}) }); }
@Override public boolean onTouchEvent(MotionEvent event) { if (!isEnabled()) return false; switch (event.getAction()) { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (!knobState) { innerContentAnimator = ObjectAnimator.ofFloat(AnSwitch.this, innerContentProperty, innerContentRate, 1.0F); innerContentAnimator.setDuration(300L); innerContentAnimator.setInterpolator(new DecelerateInterpolator()); innerContentAnimator.start(); } knobExpandAnimator = ObjectAnimator.ofFloat(AnSwitch.this, knobExpandProperty, knobExpandRate, 0.0F); knobExpandAnimator.setDuration(300L); knobExpandAnimator.setInterpolator(new DecelerateInterpolator()); knobExpandAnimator.start(); mIsChecked = knobState; if (AnSwitch.this.onSwitchStateChangeListener != null && mIsChecked != preIsOn) { AnSwitch.this.onSwitchStateChangeListener.onSwitchStateChange(mIsChecked); } break; } return gestureDetector.onTouchEvent(event); }
private void createDefaultIconAnimation() { ObjectAnimator collapseAnimator = ObjectAnimator.ofFloat( mImageToggle, "rotation", mLabelsPosition == LABELS_POSITION_LEFT ? OPENED_PLUS_ROTATION_LEFT : OPENED_PLUS_ROTATION_RIGHT, CLOSED_PLUS_ROTATION); ObjectAnimator expandAnimator = ObjectAnimator.ofFloat( mImageToggle, "rotation", CLOSED_PLUS_ROTATION, mLabelsPosition == LABELS_POSITION_LEFT ? OPENED_PLUS_ROTATION_LEFT : OPENED_PLUS_ROTATION_RIGHT); mOpenAnimatorSet.play(expandAnimator); mCloseAnimatorSet.play(collapseAnimator); mOpenAnimatorSet.setInterpolator(mOpenInterpolator); mCloseAnimatorSet.setInterpolator(mCloseInterpolator); mOpenAnimatorSet.setDuration(ANIMATION_DURATION); mCloseAnimatorSet.setDuration(ANIMATION_DURATION); }
@Override public void prepare(View target) { getAnimatorAgent() .playTogether( ObjectAnimator.ofFloat(target, "alpha", 1, 0), ObjectAnimator.ofFloat(target, "translationX", 0, -target.getWidth() / 4)); }
/** 下落 */ public void freeFall() { ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(shapeLoadingView, "translationY", 0, mDistance); ObjectAnimator scaleIndication = ObjectAnimator.ofFloat(indicationIm, "scaleX", 1, 0.2f); objectAnimator.setDuration(ANIMATION_DURATION); objectAnimator.setInterpolator(new AccelerateInterpolator()); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.setDuration(ANIMATION_DURATION); animatorSet.playTogether(objectAnimator, scaleIndication); animatorSet.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) {} @Override public void onAnimationEnd(Animator animation) { shapeLoadingView.changeShape(); upThrow(); } @Override public void onAnimationCancel(Animator animation) {} @Override public void onAnimationRepeat(Animator animation) {} }); animatorSet.start(); }
private void animateHide() { bubbleHideAnimator = new AnimatorSet(); this.setPivotX(this.getWidth()); this.setPivotY(this.getHeight()); Animator shrinkerX = ObjectAnimator.ofFloat(this, SCALE_X, 1f, 0f).setDuration(BUBBLE_ANIMATION_DURATION); Animator shrinkerY = ObjectAnimator.ofFloat(this, SCALE_Y, 1f, 0f).setDuration(BUBBLE_ANIMATION_DURATION); Animator alpha = ObjectAnimator.ofFloat(this, ALPHA, 1f, 0f).setDuration(BUBBLE_ANIMATION_DURATION); bubbleHideAnimator.setInterpolator(new AccelerateInterpolator()); bubbleHideAnimator.playTogether(shrinkerX, shrinkerY, alpha); bubbleHideAnimator.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); FastScrollBubble.this.setVisibility(INVISIBLE); bubbleHideAnimator = null; } @Override public void onAnimationCancel(Animator animation) { super.onAnimationCancel(animation); FastScrollBubble.this.setVisibility(INVISIBLE); bubbleHideAnimator = null; } }); bubbleHideAnimator.start(); }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @SuppressLint("NewApi") private void init() { mXAnimator = ObjectAnimator.ofFloat(this, "x", 0); mYAnimator = ObjectAnimator.ofFloat(this, "y", 0); mWAnimator = ObjectAnimator.ofInt(this, "wid", 0); mHAnimator = ObjectAnimator.ofInt(this, "hei", 0); mAnimatorSet = new AnimatorSet(); mAnimatorSet.setDuration(AnimationDuration); mAnimatorSet.playTogether(mWAnimator, mHAnimator, mXAnimator, mYAnimator); mAnimatorSet.addListener( new AnimatorListener() { @Override public void onAnimationStart(Animator animation) {} @Override public void onAnimationRepeat(Animator animation) {} @Override public void onAnimationEnd(Animator animation) { if (getVisibility() != View.VISIBLE) { setVisibility(View.VISIBLE); } } @Override public void onAnimationCancel(Animator animation) {} }); }
void hide() { Xlog.i(TAG, "bottom bar hide(), showing: " + mShowing); if (mUseQuickControls || mUseFullScreen) { cancelBottomBarAnimation(); int visibleHeight = getVisibleBottomHeight(); float startPos = getTranslationY(); this.setLayerType(View.LAYER_TYPE_HARDWARE, null); mBottomBarAnimator = ObjectAnimator.ofFloat(this, "translationY", startPos, startPos + visibleHeight); mBottomBarAnimator.addListener(mHideBottomBarAnimatorListener); setupBottomBarAnimator(mBottomBarAnimator); mBottomBarAnimator.start(); this.setVisibility(View.GONE); mShowing = false; return; } else { this.setVisibility(View.VISIBLE); cancelBottomBarAnimation(); int visibleHeight = getVisibleBottomHeight(); float startPos = getTranslationY(); Xlog.i(TAG, "hide(): visibleHeight: " + visibleHeight); Xlog.i(TAG, "hide(): startPos: " + startPos); this.setLayerType(View.LAYER_TYPE_HARDWARE, null); mBottomBarAnimator = ObjectAnimator.ofFloat(this, "translationY", startPos, startPos + visibleHeight); mBottomBarAnimator.addListener(mHideBottomBarAnimatorListener); setupBottomBarAnimator(mBottomBarAnimator); mBottomBarAnimator.start(); } mShowing = false; }
private void updateButtonState(SendButtonState buttonState) { if (mButtonState != buttonState) { mButtonState = buttonState; float translation = Units.dpToPx(mContext, 14) / 3; float barRotation1 = mButtonBar1.getRotation(); float barTranslation1 = mButtonBar1.getTranslationY(); float barRotation2 = mButtonBar2.getRotation(); float barTranslation2 = mButtonBar2.getTranslationY(); float barRotationTarget1 = mButtonState == SendButtonState.ATTACH ? 0 : 225; float barTranslationTarget1 = mButtonState == SendButtonState.SEND ? -translation : 0; float barRotationTarget2 = mButtonState == SendButtonState.ATTACH ? 90 : 135; float barTranslationTarget2 = mButtonState == SendButtonState.SEND ? translation : 0; ObjectAnimator.ofFloat(mButtonBar1, "rotation", barRotation1, barRotationTarget1) .setDuration(ANIMATION_DURATION) .start(); ObjectAnimator.ofFloat(mButtonBar2, "rotation", barRotation2, barRotationTarget2) .setDuration(ANIMATION_DURATION) .start(); ObjectAnimator.ofFloat(mButtonBar1, "translationY", barTranslation1, barTranslationTarget1) .setDuration(ANIMATION_DURATION) .start(); ObjectAnimator.ofFloat(mButtonBar2, "translationY", barTranslation2, barTranslationTarget2) .setDuration(ANIMATION_DURATION) .start(); } }
/** * ��ת���� * * @param one * @param two */ private void flipit(View one, View two) { final View visible; final View invisible; if (one.getVisibility() == View.GONE) { visible = two; invisible = one; } else { invisible = two; visible = one; } ObjectAnimator visToInvis = ObjectAnimator.ofFloat(visible, "rotationY", 0f, 90f); visToInvis.setDuration(500); visToInvis.setInterpolator(accelerator); final ObjectAnimator invisToVis = ObjectAnimator.ofFloat(invisible, "rotationY", -90f, 0f); invisToVis.setDuration(500); invisToVis.setInterpolator(decelerator); visToInvis.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator anim) { visible.setVisibility(View.GONE); invisToVis.start(); invisible.setVisibility(View.VISIBLE); } }); visToInvis.start(); }
private void startAnimation(View img, final Intent intent) { // ObjectAnimator oaTranslationX = ObjectAnimator.ofFloat(img, // "translationX", 0, mScreenWidth / 2); // ObjectAnimator oaTranslationY = ObjectAnimator.ofFloat(img, // "translationY", 0, mScreenHeight / 2); ObjectAnimator oaScaleX = ObjectAnimator.ofFloat(img, "scaleX", 0.5f, 1.2f, 1f); ObjectAnimator oaScaleY = ObjectAnimator.ofFloat(img, "scaleY", 0.5f, 1.2f, 1f); // oaTranslationX.setDuration(1000); // oaTranslationY.setDuration(1000); // oaScaleX.setDuration(1000); // oaScaleY.setDuration(1000); AnimatorSet set = new AnimatorSet(); set.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { isLocked = true; super.onAnimationStart(animation); } @Override public void onAnimationEnd(Animator animation) { Log.e("", "动画完成"); isLocked = false; startActivity(intent); } }); set.play(oaScaleX).with(oaScaleY); set.setDuration(500); if (!isLocked) { set.start(); } }
private ViewFader(View view) { mView = Preconditions.checkNotNull(view); mFadeOutAnimation = ObjectAnimator.ofFloat(view, View.ALPHA, 1, 0).setDuration(FADE_OUT_DURATION); mFadeInAnimation = ObjectAnimator.ofFloat(view, View.ALPHA, 0, 1).setDuration(FADE_IN_DURATION); }
@Override public void prepare(View target) { getAnimatorAgent() .playTogether( ObjectAnimator.ofFloat(target, "alpha", 0, 1), ObjectAnimator.ofFloat(target, "translationY", -target.getHeight() / 4, 0)); }
private void flip(final View v1, final View v2, final boolean scale, boolean reverse) { final int duration = 300; final int degree = reverse ? 90 : -90; final int degree2 = -degree; final ObjectAnimator a, b; if (!scale) { a = ObjectAnimator.ofFloat(v1, "rotationY", 0, degree); b = ObjectAnimator.ofFloat(v2, "rotationY", degree2, 0); } else { final float scaleX = 0.5f; final float scaleY = 0.5f; a = ObjectAnimator.ofPropertyValuesHolder( v1, PropertyValuesHolder.ofFloat("rotationY", 0, degree), PropertyValuesHolder.ofFloat("scaleX", 1, scaleX), PropertyValuesHolder.ofFloat("scaleY", 1, scaleY)); b = ObjectAnimator.ofPropertyValuesHolder( v2, PropertyValuesHolder.ofFloat("rotationY", degree2, 0), PropertyValuesHolder.ofFloat("scaleX", scaleX, 1), PropertyValuesHolder.ofFloat("scaleY", scaleY, 1)); } a.setInterpolator(new LinearInterpolator()); b.setInterpolator(new LinearInterpolator()); a.setDuration(duration); b.setDuration(duration); a.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) {} @Override public void onAnimationEnd(Animator animation) { v1.setVisibility(View.GONE); v2.setVisibility(View.VISIBLE); if (scale) { // 恢复scale v1.setScaleX(1); v1.setScaleY(1); } } @Override public void onAnimationCancel(Animator animation) {} @Override public void onAnimationRepeat(Animator animation) {} }); v1.setVisibility(View.VISIBLE); v2.setVisibility(View.GONE); AnimatorSet set = new AnimatorSet(); set.play(a).before(b); set.start(); }