android.animation.PropertyValuesHolder#ofFloat ( )源码实例Demo

下面列出了android.animation.PropertyValuesHolder#ofFloat ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: TheGlowingLoader   文件: RippleAnimator.java
public void startCircleMajor(final Callback callback) {
    PropertyValuesHolder rp = PropertyValuesHolder.ofFloat("radius", 0, circleMaxRadius);
    PropertyValuesHolder ap = PropertyValuesHolder.ofFloat("alpha", 1, 0);
    PropertyValuesHolder sp = PropertyValuesHolder.ofInt("stroke", (int) (circleMaxRadius * .15f), 0);

    ValueAnimator va = ValueAnimator.ofPropertyValuesHolder(rp, ap, sp);
    va.setInterpolator(new AccelerateInterpolator(.4f));
    va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            circleRadius = (float) animation.getAnimatedValue("radius");
            circleAlpha = (float) animation.getAnimatedValue("alpha");
            circleStroke = (int) animation.getAnimatedValue("stroke");
            callback.onValueUpdated();
        }
    });
    va.setDuration(450);
    va.start();
}
 
@Override
public Animator getInAnimator(View target, SlideShowView parent, int fromSlide, int toSlide) {
    target.setAlpha(0);
    target.setScaleX(SCALE_FACTOR);
    target.setScaleY(SCALE_FACTOR);
    target.setTranslationX(0);
    target.setTranslationY(0);
    target.setRotationX(0);
    target.setRotationY(0);

    final PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat(View.SCALE_X, 1);
    final PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 1);
    final PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat(View.ALPHA, 1);

    ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(target, scaleX, scaleY, alpha);
    animator.setDuration(getDuration());
    animator.setInterpolator(getInterpolator());

    return animator;
}
 
private void animStart(float velocityX, float velocityY) {
    animCancel();

    PropertyValuesHolder hvx = PropertyValuesHolder.ofFloat("vx", velocityX, 0);
    PropertyValuesHolder hvy = PropertyValuesHolder.ofFloat("vy", velocityY, 0);
    valueAnimator = ValueAnimator.ofPropertyValuesHolder(hvx, hvy).setDuration(mFlingConfig.getDuring());
    valueAnimator.setInterpolator(mFlingConfig.getInterpolator());
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        private long lastTime = 0;

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            long now = animation.getCurrentPlayTime();
            long dur = (now - lastTime);
            float sx = (float) animation.getAnimatedValue("vx") * dur / -1000 * mFlingConfig.getSensitivity();
            float sy = (float) animation.getAnimatedValue("vy") * dur / -1000 * mFlingConfig.getSensitivity();
            lastTime = now;

            if (mAdvanceGestureListener != null){
                mAdvanceGestureListener.onDrag(scaled(sx), scaled(sy));
            }
        }
    });
    valueAnimator.start();
}
 
源代码4 项目: LittleFreshWeather   文件: CityWeatherActivity.java
@Override
public void run() {
    ++mSpecialWeatherNumRain;
    if (mSpecialWeatherNumRain <= mSpecialWeatherNumLimitRain) {
        int screenHeight = DensityUtil.getScreenHeight(CityWeatherActivity.this);
        int screenWidth = DensityUtil.getScreenWidth(CityWeatherActivity.this);
        int fX = mRandom.nextInt(screenWidth << 1);
        int tX = fX - (int)(screenHeight * 0.58);

        ImageView imageView = new ImageView(CityWeatherActivity.this);
        imageView.setVisibility(View.VISIBLE);
        mPresenter.getImageViewSrc(imageView, mRainIconId);
        //imageView.setImageResource(mRainIconId);
        imageView.setRotation(30);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(fX, 0, 0, 0);
        rlBackgroundView.addView(imageView, layoutParams);

        PropertyValuesHolder holderY = PropertyValuesHolder.ofFloat("translationY", -100, screenHeight + 100);
        PropertyValuesHolder holderX = PropertyValuesHolder.ofFloat("translationX", fX, tX);
        ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(imageView, holderX, holderY);
        if ((mSpecialWeatherNumRain & 0x1) == 0) {
            animator.setDuration(mSpecialWeatherSpeedLimitRain);
        } else {
            animator.setDuration(mSpecialWeatherSpeedLimitRain + RAIN_SPEED_OFFSET);
        }
        animator.setRepeatMode(ObjectAnimator.RESTART);
        animator.setRepeatCount(ObjectAnimator.INFINITE);
        animator.setInterpolator(new LinearInterpolator());
        animator.start();

        mHandler.postDelayed(rainProc, RAIN_GEN_INTERVAL);
    }
}
 
源代码5 项目: TurboLauncher   文件: Workspace.java
private void fadeAndRemoveEmptyScreen(int delay, int duration, final Runnable onComplete,
        final boolean stripEmptyScreens) {
     
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0f);
    PropertyValuesHolder bgAlpha = PropertyValuesHolder.ofFloat("backgroundAlpha", 0f);

    final CellLayout cl = mWorkspaceScreens.get(EXTRA_EMPTY_SCREEN_ID);

    mRemoveEmptyScreenRunnable = new Runnable() {
        @Override
        public void run() {
            if (hasExtraEmptyScreen()) {
                mWorkspaceScreens.remove(EXTRA_EMPTY_SCREEN_ID);
                mScreenOrder.remove(EXTRA_EMPTY_SCREEN_ID);
                removeView(cl);
                if (stripEmptyScreens) {
                    stripEmptyScreens();
                }
            }
        }
    };

    ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(cl, alpha, bgAlpha);
    oa.setDuration(duration);
    oa.setStartDelay(delay);
    oa.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (mRemoveEmptyScreenRunnable != null) {
                mRemoveEmptyScreenRunnable.run();
            }
            if (onComplete != null) {
                onComplete.run();
            }
        }
    });
    oa.start();
}
 
源代码6 项目: Flubber   文件: SlideDown.java
@Override
public Animator getAnimationFor(AnimationBody animationBody, View view) {

    final float startY = DimensionUtils.dp2px(-800);
    final float endY = 0f;

    final PropertyValuesHolder translationPVH =
            PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, startY, endY);

    final ObjectAnimator animation =
            ObjectAnimator.ofPropertyValuesHolder(view, translationPVH);

    return animation;
}
 
源代码7 项目: LiveGiftLayout   文件: GiftFrameLayout.java
public void firstHideLayout() {
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f, 0f);
    ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(GiftFrameLayout.this, alpha);
    animator.setStartDelay(0);
    animator.setDuration(0);
    animator.start();
}
 
@NonNull
public static <T> ObjectAnimator ofFloat(@Nullable T target,
                                         @NonNull Property<T, Float> xProperty,
                                         @NonNull Property<T, Float> yProperty,
                                         @NonNull Path path) {

    float[] xValues = new float[NUM_POINTS];
    float[] yValues = new float[NUM_POINTS];
    calculateXYValues(path, xValues, yValues);

    PropertyValuesHolder xPvh = PropertyValuesHolder.ofFloat(xProperty, xValues);
    PropertyValuesHolder yPvh = PropertyValuesHolder.ofFloat(yProperty, yValues);

    return ObjectAnimator.ofPropertyValuesHolder(target, xPvh, yPvh);
}
 
源代码9 项目: LiveGiftLayout   文件: GiftAnimationUtil.java
/**
 * @param target
 * @return 送礼数字变化
 */
public static ObjectAnimator scaleGiftNum(final TextView target) {
    PropertyValuesHolder anim4 = PropertyValuesHolder.ofFloat("scaleX",
            1.2f, 0.8f, 1f);
    PropertyValuesHolder anim5 = PropertyValuesHolder.ofFloat("scaleY",
            1.2f, 0.8f, 1f);
    PropertyValuesHolder anim6 = PropertyValuesHolder.ofFloat("alpha",
            1.0f, 0f, 1f);
    ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(target, anim4, anim5, anim6).setDuration(400);
    return animator;

}
 
/**
 * ObjectAnimator: You can also create multiple animations by PropertyValuesHolder.
 * <p>
 * ValueAnimator has the same method, but we don't use it that way. #ValueAnimator.ofPropertyValuesHolder()#
 *
 * @return
 */
public Animator getObjectAnimatorByPropertyValuesHolder() {
    PropertyValuesHolder bgColorAnimator = PropertyValuesHolder.ofObject("backgroundColor",
            new ArgbEvaluator(),
            0xff009688, 0xff795548);
    PropertyValuesHolder rotationXAnimator = PropertyValuesHolder.ofFloat("rotationX",
            0f, 360f);
    ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(mPuppet, bgColorAnimator, rotationXAnimator);
    objectAnimator.setDuration(3000);
    objectAnimator.setRepeatCount(1);
    objectAnimator.setRepeatMode(ValueAnimator.REVERSE);
    return objectAnimator;
}
 
源代码11 项目: delion   文件: StackViewAnimation.java
private Animator createNewTabOpenedAnimator(
        StackTab[] tabs, ViewGroup container, TabModel model, int focusIndex) {
    Tab tab = model.getTabAt(focusIndex);
    if (tab == null || !tab.isNativePage()) return null;

    View view = tab.getView();
    if (view == null) return null;

    // Set up the view hierarchy
    if (view.getParent() != null) ((ViewGroup) view.getParent()).removeView(view);
    ViewGroup bgView = new FrameLayout(view.getContext());
    bgView.setBackgroundColor(tab.getBackgroundColor());
    bgView.addView(view);
    container.addView(
            bgView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    // Update any compositor state that needs to change
    if (tabs != null && focusIndex >= 0 && focusIndex < tabs.length) {
        tabs[focusIndex].setAlpha(0.f);
    }

    // Build the view animations
    PropertyValuesHolder xScale = PropertyValuesHolder.ofFloat(View.SCALE_X, 0.f, 1.f);
    PropertyValuesHolder yScale = PropertyValuesHolder.ofFloat(View.SCALE_Y, 0.f, 1.f);
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat(View.ALPHA, 0.f, 1.f);
    ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(
            bgView, xScale, yScale, alpha);

    animator.setDuration(TAB_OPENED_ANIMATION_DURATION);
    animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_FOLLOW_THROUGH_CURVE);

    float insetPx = TAB_OPENED_PIVOT_INSET_DP * mDpToPx;

    bgView.setPivotY(TAB_OPENED_PIVOT_INSET_DP);
    bgView.setPivotX(LocalizationUtils.isLayoutRtl() ? mWidthDp * mDpToPx - insetPx : insetPx);
    return animator;
}
 
@Override
public void animateMenuClosing(Point center) {
    super.animateMenuClosing(center);
    setAnimating(true);

    Animator lastAnimation = null;
    for (int i = 0; i <menu.getSubActionItems().size(); i++) {
        PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat(View.TRANSLATION_X, -(menu.getSubActionItems().get(i).x - center.x + menu.getSubActionItems().get(i).width / 2));
        PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, -(menu.getSubActionItems().get(i).y - center.y + menu.getSubActionItems().get(i).height / 2)-DIST);
        PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, -730);
        PropertyValuesHolder pvhsX = PropertyValuesHolder.ofFloat(View.SCALE_X,2, 1,0);
        PropertyValuesHolder pvhsY = PropertyValuesHolder.ofFloat(View.SCALE_Y,2, 1,0);
        PropertyValuesHolder pvhA = PropertyValuesHolder.ofFloat(View.ALPHA, 0);

        final ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(menu.getSubActionItems().get(i).view, pvhX, pvhY, pvhR, pvhsX, pvhsY, pvhA);
        animation.setDuration(DURATION);
        animation.setInterpolator(new AccelerateDecelerateInterpolator());
        animation.addListener(new SubActionItemAnimationListener(menu.getSubActionItems().get(i), ActionType.CLOSING));

        if(i == 0) {
            lastAnimation = animation;
        }

        animation.setStartDelay((i) * LAG_BETWEEN_ITEMS);
        animation.start();
    }
    if(lastAnimation != null) {
        lastAnimation.addListener(new LastAnimationListener());
    }
}
 
源代码13 项目: fingerpoetry-android   文件: DragItem.java
void startDrag(View startFromView, float touchX, float touchY) {
    show();
    onBindDragView(startFromView, mDragView);
    onMeasureDragView(startFromView, mDragView);
    onStartDragAnimation(mDragView);

    float startX = startFromView.getX() - (mDragView.getMeasuredWidth() - startFromView.getMeasuredWidth()) / 2 + mDragView
            .getMeasuredWidth() / 2;
    float startY = startFromView.getY() - (mDragView.getMeasuredHeight() - startFromView.getMeasuredHeight()) / 2 + mDragView
            .getMeasuredHeight() / 2;

    if (mSnapToTouch) {
        mPosTouchDx = 0;
        mPosTouchDy = 0;
        setPosition(touchX, touchY);
        setAnimationDx(startX - touchX);
        setAnimationDY(startY - touchY);

        PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("AnimationDx", mAnimationDx, 0);
        PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("AnimationDY", mAnimationDy, 0);
        ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(this, pvhX, pvhY);
        anim.setInterpolator(new DecelerateInterpolator());
        anim.setDuration(ANIMATION_DURATION);
        anim.start();
    } else {
        mPosTouchDx = startX - touchX;
        mPosTouchDy = startY - touchY;
        setPosition(touchX, touchY);
    }
}
 
源代码14 项目: LazyRecyclerAdapter   文件: SquareSpinIndicator.java
@Override
public List<Animator> createAnimation() {
    List<Animator> animators = new ArrayList<>();
    PropertyValuesHolder rotation5 = PropertyValuesHolder.ofFloat("rotationX", 0, 180, 180, 0, 0);
    PropertyValuesHolder rotation6 = PropertyValuesHolder.ofFloat("rotationY", 0, 0, 180, 180, 0);
    ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(getTarget(), rotation6, rotation5);
    animator.setInterpolator(new LinearInterpolator());
    animator.setRepeatCount(-1);
    animator.setDuration(2500);
    animator.start();
    animators.add(animator);
    return animators;
}
 
@NonNull
public static ObjectAnimator ofFloat(@Nullable Object target, @NonNull String xPropertyName,
                                     @NonNull String yPropertyName, @NonNull Path path) {

    float[] xValues = new float[NUM_POINTS];
    float[] yValues = new float[NUM_POINTS];
    calculateXYValues(path, xValues, yValues);

    PropertyValuesHolder xPvh = PropertyValuesHolder.ofFloat(xPropertyName, xValues);
    PropertyValuesHolder yPvh = PropertyValuesHolder.ofFloat(yPropertyName, yValues);

    return ObjectAnimator.ofPropertyValuesHolder(target, xPvh, yPvh);
}
 
源代码16 项目: Reachability   文件: CustomAnimationActivity.java
private PropertyValuesHolder[] toRightAnimation() {

        PropertyValuesHolder holderX = PropertyValuesHolder.ofFloat( "translationX", 0f, getWidth() );
        PropertyValuesHolder holderR = PropertyValuesHolder.ofFloat("rotation", 0f, 360f);
        PropertyValuesHolder[] holders = {holderX, holderR};
        return holders;
    }
 
源代码17 项目: UltimateAndroid   文件: DefaultAnimationHandler.java
@Override
public void animateMenuOpening(Point center) {
    super.animateMenuOpening(center);

    setAnimating(true);

    Animator lastAnimation = null;
    for (int i = 0; i < menu.getSubActionItems().size(); i++) {

        menu.getSubActionItems().get(i).view.setScaleX(0);
        menu.getSubActionItems().get(i).view.setScaleY(0);
        menu.getSubActionItems().get(i).view.setAlpha(0);

        PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat(View.TRANSLATION_X, menu.getSubActionItems().get(i).x - center.x + menu.getSubActionItems().get(i).width / 2);
        PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, menu.getSubActionItems().get(i).y - center.y + menu.getSubActionItems().get(i).height / 2);
        PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, 720);
        PropertyValuesHolder pvhsX = PropertyValuesHolder.ofFloat(View.SCALE_X, 1);
        PropertyValuesHolder pvhsY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 1);
        PropertyValuesHolder pvhA = PropertyValuesHolder.ofFloat(View.ALPHA, 1);

        final ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(menu.getSubActionItems().get(i).view, pvhX, pvhY, pvhR, pvhsX, pvhsY, pvhA);
        animation.setDuration(DURATION);
        animation.setInterpolator(new OvershootInterpolator(0.9f));
        animation.addListener(new SubActionItemAnimationListener(menu.getSubActionItems().get(i), ActionType.OPENING));

        if(i == 0) {
            lastAnimation = animation;
        }

        // Put a slight lag between each of the menu items to make it asymmetric
        animation.setStartDelay((menu.getSubActionItems().size() - i) * LAG_BETWEEN_ITEMS);
        animation.start();
    }
    if(lastAnimation != null) {
        lastAnimation.addListener(new LastAnimationListener());
    }

}
 
源代码18 项目: AndroidChromium   文件: StackViewAnimation.java
private Animator createNewTabOpenedAnimator(
        StackTab[] tabs, ViewGroup container, TabModel model, int focusIndex) {
    Tab tab = model.getTabAt(focusIndex);
    if (tab == null || !tab.isNativePage()) return null;

    View view = tab.getView();
    if (view == null) return null;

    // Set up the view hierarchy
    if (view.getParent() != null) ((ViewGroup) view.getParent()).removeView(view);
    ViewGroup bgView = new FrameLayout(view.getContext());
    bgView.setBackgroundColor(tab.getBackgroundColor());
    bgView.addView(view);
    container.addView(
            bgView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    // Update any compositor state that needs to change
    if (tabs != null && focusIndex >= 0 && focusIndex < tabs.length) {
        tabs[focusIndex].setAlpha(0.f);
    }

    // Build the view animations
    PropertyValuesHolder xScale = PropertyValuesHolder.ofFloat(View.SCALE_X, 0.f, 1.f);
    PropertyValuesHolder yScale = PropertyValuesHolder.ofFloat(View.SCALE_Y, 0.f, 1.f);
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat(View.ALPHA, 0.f, 1.f);
    ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(
            bgView, xScale, yScale, alpha);

    animator.setDuration(TAB_OPENED_ANIMATION_DURATION);
    animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_FOLLOW_THROUGH_CURVE);

    float insetPx = TAB_OPENED_PIVOT_INSET_DP * mDpToPx;

    bgView.setPivotY(TAB_OPENED_PIVOT_INSET_DP);
    bgView.setPivotX(LocalizationUtils.isLayoutRtl() ? mWidthDp * mDpToPx - insetPx : insetPx);
    return animator;
}
 
源代码19 项目: ArcLayout   文件: AnimatorUtils.java
public static PropertyValuesHolder scaleY(float... values) {
  return PropertyValuesHolder.ofFloat(SCALE_Y, values);
}
 
源代码20 项目: Qiitanium   文件: AnimatorUtils.java
public static PropertyValuesHolder ofRotation(float... values) {
  return PropertyValuesHolder.ofFloat(ROTATION, values);
}