com.nineoldandroids.view.ViewPropertyAnimator类的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(130)

本文整理了Java中com.nineoldandroids.view.ViewPropertyAnimator类的一些代码示例,展示了ViewPropertyAnimator类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ViewPropertyAnimator类的具体详情如下:
包路径:com.nineoldandroids.view.ViewPropertyAnimator
类名称:ViewPropertyAnimator

ViewPropertyAnimator介绍

[英]This class enables automatic and optimized animation of select properties on View objects. If only one or two properties on a View object are being animated, then using an android.animation.ObjectAnimator is fine; the property setters called by ObjectAnimator are well equipped to do the right thing to set the property and invalidate the view appropriately. But if several properties are animated simultaneously, or if you just want a more convenient syntax to animate a specific property, then ViewPropertyAnimator might be more well-suited to the task.

This class may provide better performance for several simultaneous animations, because it will optimize invalidate calls to take place only once for several properties instead of each animated property independently causing its own invalidation. Also, the syntax of using this class could be easier to use because the caller need only tell the View object which property to animate, and the value to animate either to or by, and this class handles the details of configuring the underlying Animator class and starting it.

This class is not constructed by the caller, but rather by the View whose properties it will animate. Calls to android.view.View#animate() will return a reference to the appropriate ViewPropertyAnimator object for that View.
[中]此类启用视图对象上选择属性的自动和优化动画。如果视图对象上只有一个或两个属性被设置动画,那么使用android。动画动画师很好;ObjectAnimator调用的属性设置程序能够正确设置属性并适当地使视图无效。但是,如果同时设置了多个属性的动画,或者您只想使用更方便的语法设置特定属性的动画,那么ViewPropertyImator可能更适合该任务。
此类可能会为多个同时进行的动画提供更好的性能,因为它将优化多个属性的无效调用,使其仅发生一次,而不是每个动画属性单独导致其自身的无效。此外,使用此类的语法可能更容易使用,因为调用方只需告诉View对象要设置动画的属性,以及要设置动画的值,该类处理配置基础Animator类并启动它的细节。
这个类不是由调用方构造的,而是由它将为其属性设置动画的视图构造的。给安卓打电话。看法View#animate()将返回对该视图的相应ViewPropertyImator对象的引用。

代码示例

代码示例来源:origin: wangdan/AisenWeiBo

/**
 * Lifting view
 *
 * @param view The animation target
 * @param baseRotation initial Rotation X in 3D space
 * @param fromY initial Y position of view
 * @param duration aniamtion duration
 * @param startDelay start delay before animation begin
 */
@Deprecated
public static void liftingFromBottom(View view, float baseRotation, float fromY, int duration, int startDelay){
  ViewHelper.setRotationX(view, baseRotation);
  ViewHelper.setTranslationY(view, fromY);
  ViewPropertyAnimator
      .animate(view)
      .setInterpolator(new AccelerateDecelerateInterpolator())
      .setDuration(duration)
      .setStartDelay(startDelay)
      .rotationX(0)
      .translationY(0)
      .start();
}

代码示例来源:origin: Zomato/AndroidPhotoFilters

private void setAnimation(View viewToAnimate, int position) {
  {
    ViewHelper.setAlpha(viewToAnimate, .0f);
    com.nineoldandroids.view.ViewPropertyAnimator.animate(viewToAnimate).alpha(1).setDuration(250).start();
    lastPosition = position;
  }
}

代码示例来源:origin: commonsguy/cw-omnibus

@TargetApi(11)
private void translateWidgets(int deltaX, View... views) {
 for (final View v : views) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
   v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
  }
  ViewPropertyAnimator.animate(v).translationXBy(deltaX)
            .setDuration(ANIM_DURATION)
            .setListener(new AnimatorListenerAdapter() {
             @Override
             public void onAnimationEnd(Animator animation) {
              if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
               v.setLayerType(View.LAYER_TYPE_NONE,
                       null);
              }
             }
            });
 }
}

代码示例来源:origin: navasmdc/MaterialDesignLibrary

@Override
public void onScrollStateChanged(AbsListView absListView, int scrollState) {
  switch (scrollState) {
    case AbsListView.SCROLL_AXIS_NONE:
      floatHiding = false;
      floatShowing = false;
      ViewPropertyAnimator.animate(view).translationY(0).setDuration(300);
      break;
  }
  if (onScrollListener != null)
    onScrollListener.onScrollStateChanged(absListView, scrollState);
}

代码示例来源:origin: aa112901/remusic

private void showToolbar() {
  float headerTranslationY = ViewHelper.getTranslationY(mHeaderView);
  if (headerTranslationY != 0) {
    ViewPropertyAnimator.animate(mHeaderView).cancel();
    ViewPropertyAnimator.animate(mHeaderView).translationY(0).setDuration(200).start();
  }
  propagateToolbarState(true);
}

代码示例来源:origin: DickyQie/android-shoppingcart

/**
 * @param view
 *            所要移动的视图
 * @param deltaX
 *            最终移动的距离
 */
public void generateRevealAnimate(final View view, float deltaX) {
  int moveTo = 0;
  moveTo = (int) deltaX;
  animate(view).translationX(moveTo).setDuration(10)
      .setListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
        }
      });
}

代码示例来源:origin: code-mc/loadtoast

private void slideUp(int startDelay){
    mReAttached = false;

    ViewPropertyAnimator.animate(mView).setStartDelay(startDelay).alpha(0f)
        .translationY(-mView.getHeight() + mTranslationY)
        .setInterpolator(new AccelerateInterpolator())
        .setDuration(300)
        .setListener(new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            if(!mReAttached){
              cleanup();
            }
          }
        })
        .start();

    mVisible = false;
  }
}

代码示例来源:origin: wangdan/AisenWeiBo

ViewPropertyAnimator.animate(fabBtn).setInterpolator(mInterpolator)
      .setDuration(TRANSLATE_DURATION_MILLIS)
      .translationY(translationY);
} else {
  ViewHelper.setTranslationY(fabBtn, translationY);

代码示例来源:origin: StannyBing/ZXUtils

ViewPropertyAnimator.animate(mViewPager)
  .setDuration(duration)
  .setInterpolator(new AccelerateInterpolator())
  .scaleX((float) thumbnailWidth / mViewPager.getWidth())
  .scaleY((float) thumbnailHeight / mViewPager.getHeight())
  .translationX(thumbnailLeft)
  .translationY(thumbnailTop)
  .setListener(new Animator.AnimatorListener() {
   @Override public void onAnimationStart(Animator animation) {

代码示例来源:origin: commonsguy/cw-omnibus

@Override
 public void run() {
  if (fadingOut) {
   animate(fadee).alpha(0).setDuration(PERIOD);
   fadee.setText(R.string.fading_out);
  }
  else {
   animate(fadee).alpha(1).setDuration(PERIOD);
   fadee.setText(R.string.coming_back);
  }

  fadingOut=!fadingOut;

  fadee.postDelayed(this, PERIOD);
 }
}

代码示例来源:origin: livroandroid/5ed

public void onClickAnimar(View view) {
    animate(img).xBy(200).yBy(200).rotation(180).alpha(0.5F).setDuration(2000);
  }
}

代码示例来源:origin: ksoichiro/Android-ObservableScrollView

@Override
public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
  if (dragging) {
    int toolbarHeight = mToolbarView.getHeight();
    float currentHeaderTranslationY = ViewHelper.getTranslationY(mHeaderView);
    if (firstScroll) {
      if (-toolbarHeight < currentHeaderTranslationY) {
        mBaseTranslationY = scrollY;
      }
    }
    float headerTranslationY = ScrollUtils.getFloat(-(scrollY - mBaseTranslationY), -toolbarHeight, 0);
    ViewPropertyAnimator.animate(mHeaderView).cancel();
    ViewHelper.setTranslationY(mHeaderView, headerTranslationY);
  }
}

代码示例来源:origin: livroandroid/5ed

@Override
  public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,float velocityY)  {
    // Usuário fez um gesto de swipe lateral
    try {
      if (e1.getX() - e2.getX() > swipeMinDistance && Math.abs(velocityX) >
          swipeThreasholdVelocity) {
        // Fez um gesto da direita para a esquerda
        text.setText("<<< Left");
        animate(img).xBy(-100);
      } else if (e2.getX() - e1.getX() > swipeMinDistance && Math.abs(velocityX) >
          swipeThreasholdVelocity) {
        // Fez um gesto da esquerda para a direita
        text.setText("Right >>>");
        animate(img).xBy(100);
      }
    } catch (Exception e) { }
    return false;
  }
}

代码示例来源:origin: domoticz/domoticz-android

public void dismissCard(final View downView, final int position) {
  float viewWidth = downView.getMeasuredWidth();
  ++mDismissAnimationRefCount;
  animate(downView)
      .translationX(viewWidth)
      .alpha(0)
      .setDuration(mAnimationTime)
      .setListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
          performDismiss(downView, position);
        }
      });
}

代码示例来源:origin: code-mc/loadtoast

private void showInternal(){
  mView.show();
  ViewHelper.setTranslationX(mView, (mParentView.getWidth() - mView.getWidth()) / 2);
  ViewHelper.setAlpha(mView, 0f);
  ViewHelper.setTranslationY(mView, -mView.getHeight() + mTranslationY);
  //mView.setVisibility(View.VISIBLE);
  ViewPropertyAnimator.animate(mView).alpha(1f).translationY(25 + mTranslationY)
      .setInterpolator(new DecelerateInterpolator())
      .setListener(null)
      .setDuration(300).setStartDelay(0).start();
  mVisible = true;
}

代码示例来源:origin: aa112901/remusic

private void hideToolbar() {
  float headerTranslationY = ViewHelper.getTranslationY(mHeaderView);
  int toolbarHeight = mHeaderView.getHeight() - mActionBarSize - mStatusSize - tabLayout.getHeight();
  if (headerTranslationY != -toolbarHeight) {
    ViewPropertyAnimator.animate(mHeaderView).cancel();
    ViewPropertyAnimator.animate(mHeaderView).translationY(-toolbarHeight).setDuration(200).start();
  }
  propagateToolbarState(false);
}

代码示例来源:origin: xiangzhihong/zhihu

ViewPropertyAnimator.animate(img_float_btn)
      .setInterpolator(mInterpolator).setDuration(800)
      .translationY(translationY);
} else {
  ViewHelper.setTranslationY(img_float_btn, translationY);

代码示例来源:origin: StannyBing/ZXUtils

ViewPropertyAnimator.animate(mViewPager)
  .setDuration(duration)
  .scaleX(1)
  .scaleY(1)
  .translationX(0)
  .translationY(0)
  .setInterpolator(new DecelerateInterpolator());

代码示例来源:origin: navasmdc/MaterialDesignLibrary

@Override
  public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

    if (mLastFirstVisibleItem < firstVisibleItem) {
      if (floatShowing) floatShowing = false;
      if (!floatHiding) {
        ViewPropertyAnimator.animate(view).translationY(500).setDuration(300);
        floatHiding = true;
      }
    }
    if (mLastFirstVisibleItem > firstVisibleItem) {
      if (floatHiding) {
        floatHiding = false;
      }
      if (!floatShowing) {
        ViewPropertyAnimator.animate(view).translationY(0).setDuration(300);
        floatShowing = true;
      }
    }
    mLastFirstVisibleItem = firstVisibleItem;
    if (onScrollListener != null)
      onScrollListener.onScroll(absListView, firstVisibleItem, visibleItemCount, totalItemCount);
  }
}

代码示例来源:origin: aa112901/remusic

@Override
public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
  if (dragging) {
    int toolbarHeight = mHeaderView.getHeight() - mActionBarSize - mStatusSize - tabLayout.getHeight();
    float currentHeaderTranslationY = ViewHelper.getTranslationY(mHeaderView);
    if (firstScroll) {
      if (-toolbarHeight < currentHeaderTranslationY) {
        mBaseTranslationY = scrollY;
      }
    }
    float headerTranslationY = ScrollUtils.getFloat(-(scrollY - mBaseTranslationY), -toolbarHeight, 0);
    ViewPropertyAnimator.animate(mHeaderView).cancel();
    ViewHelper.setTranslationY(mHeaderView, headerTranslationY);
  }
  toolbar_bac.setImageResource(R.drawable.toolbar_background_black);
  float a = (float) scrollY / (ViewHelper.getScrollY(mHeaderView));
  toolbar_bac.setAlpha(a);
}

相关文章