android.view.animation.Animation.setDuration()方法的使用及代码示例

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

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

Animation.setDuration介绍

暂无

代码示例

代码示例来源:origin: aporter/coursera-android

private Animation inFromRightAnimation() {
  Animation inFromRight = new TranslateAnimation(
      Animation.RELATIVE_TO_PARENT, +1.0f,
      Animation.RELATIVE_TO_PARENT, 0.0f,
      Animation.RELATIVE_TO_PARENT, 0.0f,
      Animation.RELATIVE_TO_PARENT, 0.0f);
  inFromRight.setDuration(500);
  inFromRight.setInterpolator(new LinearInterpolator());
  return inFromRight;
}

代码示例来源:origin: stackoverflow.com

Animation fadeIn = new AlphaAnimation(0, 1);
fadeIn.setInterpolator(new DecelerateInterpolator()); //add this
fadeIn.setDuration(1000);

Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setInterpolator(new AccelerateInterpolator()); //and this
fadeOut.setStartOffset(1000);
fadeOut.setDuration(1000);

AnimationSet animation = new AnimationSet(false); //change to false
animation.addAnimation(fadeIn);
animation.addAnimation(fadeOut);
this.setAnimation(animation);

代码示例来源:origin: rey5137/material

private void animOut(final View v){
  Animation anim = new AlphaAnimation(1f, 0f);
  anim.setDuration(getContext().getResources().getInteger(android.R.integer.config_mediumAnimTime));
  anim.setAnimationListener(new Animation.AnimationListener() {
    @Override
    public void onAnimationStart(Animation animation) {}
    @Override
    public void onAnimationEnd(Animation animation) {
      v.setVisibility(View.GONE);
    }
    @Override
    public void onAnimationRepeat(Animation animation) {}
  });
  v.startAnimation(anim);
}

代码示例来源:origin: aporter/coursera-android

private Animation outToLeftAnimation() {
    Animation outToLeft = new TranslateAnimation(
        Animation.RELATIVE_TO_PARENT, 0.0f,
        Animation.RELATIVE_TO_PARENT, -1.0f,
        Animation.RELATIVE_TO_PARENT, 0.0f,
        Animation.RELATIVE_TO_PARENT, 0.0f);
    outToLeft.setDuration(500);
    outToLeft.setInterpolator(new LinearInterpolator());
    return outToLeft;
  }
}

代码示例来源:origin: stackoverflow.com

private void fadeOutAndHideImage(final ImageView img)
 {
  Animation fadeOut = new AlphaAnimation(1, 0);
  fadeOut.setInterpolator(new AccelerateInterpolator());
  fadeOut.setDuration(1000);

  fadeOut.setAnimationListener(new AnimationListener()
  {
      public void onAnimationEnd(Animation animation) 
      {
         img.setVisibility(View.GONE);
      }
      public void onAnimationRepeat(Animation animation) {}
      public void onAnimationStart(Animation animation) {}
  });

  img.startAnimation(fadeOut);
}

代码示例来源:origin: rey5137/material

private void animIn(final View v){
  Animation anim = new AlphaAnimation(0f, 1f);
  anim.setDuration(getContext().getResources().getInteger(android.R.integer.config_mediumAnimTime));
  anim.setAnimationListener(new Animation.AnimationListener() {
    @Override
    public void onAnimationStart(Animation animation) {
      v.setVisibility(View.VISIBLE);
    }
    @Override
    public void onAnimationEnd(Animation animation) {
    }
    @Override
    public void onAnimationRepeat(Animation animation) {
    }
  });
  v.startAnimation(anim);
}

代码示例来源:origin: scwang90/SmartRefreshLayout

@Override
public int onFinish(@NonNull RefreshLayout layout, boolean success) {
  final View thisView = this;
  thisView.clearAnimation();
  if (success) {
    thisView.startAnimation(new Animation() {{
      super.setDuration(100);
      super.setInterpolator(new AccelerateInterpolator());
    }
      @Override
      protected void applyTransformation(float interpolatedTime, Transformation t) {
        if (interpolatedTime == 1) {
          isRefreshing = false;
        }
        mFinishTransformation = interpolatedTime;
        thisView.invalidate();
      }
    });
    return 200;
  } else {
    isRefreshing = false;
    return 0;
  }
}

代码示例来源:origin: stackoverflow.com

public void onCreate(Bundle savedInstanceState) {
  final Animation animation = new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible
  animation.setDuration(500); // duration - half a second
  animation.setInterpolator(new LinearInterpolator()); // do not alter animation rate
  animation.setRepeatCount(Animation.INFINITE); // Repeat animation infinitely
  animation.setRepeatMode(Animation.REVERSE); // Reverse animation at the end so the button will fade back in
  final Button btn = (Button) findViewById(R.id.your_btn);
  btn.startAnimation(animation);
  btn.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(final View view) {
      view.clearAnimation();
    }
  });
}

代码示例来源:origin: stackoverflow.com

final Animation in = new AlphaAnimation(0.0f, 1.0f);
in.setDuration(3000);

final Animation out = new AlphaAnimation(1.0f, 0.0f);
out.setDuration(3000);

AnimationSet as = new AnimationSet(true);
as.addAnimation(out);
in.setStartOffset(3000);
as.addAnimation(in);

代码示例来源:origin: scwang90/SmartRefreshLayout

@Override
public int onFinish(@NonNull RefreshLayout layout, boolean success) {
  mIsInLoading = false;
  mAniController.stop();
  if (success && mEnableFadeAnimation) {
    final View thisView = this;
    thisView.startAnimation(new Animation() {{
      super.setDuration(250);
      super.setInterpolator(new AccelerateInterpolator());
    }
      @Override
      protected void applyTransformation(float interpolatedTime, Transformation t) {
        final View thisView = StoreHouseHeader.this;
        mProgress = (1 - interpolatedTime);
        thisView.invalidate();
        if (interpolatedTime == 1) {
          for (int i = 0; i < mItemList.size(); i++) {
            mItemList.get(i).resetPosition(mHorizontalRandomness);
          }
        }
      }
    });
    return 250;
  } else {
    for (int i = 0; i < mItemList.size(); i++) {
      mItemList.get(i).resetPosition(mHorizontalRandomness);
    }
  }
  return 0;
}

代码示例来源:origin: stackoverflow.com

Animation fadeIn = new AlphaAnimation(0, 1);
fadeIn.setInterpolator(new DecelerateInterpolator()); // add this
fadeIn.setDuration(fadeInDuration);
Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setInterpolator(new AccelerateInterpolator()); // and this
fadeOut.setStartOffset(fadeInDuration + timeBetween);
fadeOut.setDuration(fadeOutDuration);

代码示例来源:origin: rey5137/material

private void animOut(final View v, final boolean setGone, final boolean immediately){
  if(!isShowing() || v.getVisibility() != View.VISIBLE || immediately) {
    v.setVisibility(setGone ? View.GONE : View.INVISIBLE);
    return;
  }
  Animation anim = new AlphaAnimation(1f, 0f);
  anim.setDuration(getContext().getResources().getInteger(android.R.integer.config_mediumAnimTime));
  anim.setAnimationListener(new Animation.AnimationListener() {
    @Override
    public void onAnimationStart(Animation animation) {}
    @Override
    public void onAnimationEnd(Animation animation) {
      v.setVisibility(setGone ? View.GONE : View.INVISIBLE);
    }
    @Override
    public void onAnimationRepeat(Animation animation) {}
  });
  v.startAnimation(anim);
}

代码示例来源:origin: stackoverflow.com

Animation.RELATIVE_TO_PARENT, 0.0f,
      Animation.RELATIVE_TO_PARENT, 0.0f);
  inFromRight.setDuration(500);
  inFromRight.setInterpolator(new AccelerateInterpolator());
  return inFromRight;
  Animation.RELATIVE_TO_PARENT, 0.0f,
  Animation.RELATIVE_TO_PARENT, 0.0f);
outtoLeft.setDuration(500);
outtoLeft.setInterpolator(new AccelerateInterpolator());
return outtoLeft;
  Animation.RELATIVE_TO_PARENT, 0.0f,
  Animation.RELATIVE_TO_PARENT, 0.0f);
inFromLeft.setDuration(500);
inFromLeft.setInterpolator(new AccelerateInterpolator());
return inFromLeft;
  Animation.RELATIVE_TO_PARENT, 0.0f,
  Animation.RELATIVE_TO_PARENT, 0.0f);
outtoRight.setDuration(500);
outtoRight.setInterpolator(new AccelerateInterpolator());
return outtoRight;

代码示例来源:origin: androidquery/androidquery

anim = new AlphaAnimation(0, 1);
  anim.setInterpolator(new DecelerateInterpolator()); 
  anim.setDuration(FADE_DUR);
}else{

代码示例来源:origin: rey5137/material

private void animIn(final View v, boolean immediately){
  if(v.getVisibility() == View.VISIBLE)
    return;
  if(!isShowing() || immediately) {
    v.setVisibility(View.VISIBLE);
    return;
  }
  Animation anim = new AlphaAnimation(0f, 1f);
  anim.setDuration(getContext().getResources().getInteger(android.R.integer.config_mediumAnimTime));
  anim.setAnimationListener(new Animation.AnimationListener() {
    @Override
    public void onAnimationStart(Animation animation) {
      v.setVisibility(View.VISIBLE);
    }
    @Override
    public void onAnimationEnd(Animation animation) {}
    @Override
    public void onAnimationRepeat(Animation animation) {}
  });
  v.startAnimation(anim);
}

代码示例来源:origin: Aspsine/SwipeToLoadLayout

private void setupAnimations() {
  mAnimation = new Animation() {
    @Override
    public void applyTransformation(float interpolatedTime, Transformation t) {
      setRotate(interpolatedTime);
    }
  };
  mAnimation.setRepeatCount(Animation.INFINITE);
  mAnimation.setRepeatMode(Animation.RESTART);
  mAnimation.setInterpolator(LINEAR_INTERPOLATOR);
  mAnimation.setDuration(ANIMATION_DURATION);
}

代码示例来源:origin: stackoverflow.com

Animation fadeIn = new AlphaAnimation(0, 1);
fadeIn.setInterpolator(new DecelerateInterpolator()); //add this
fadeIn.setDuration(1500); //time in milliseconds

Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setInterpolator(new AccelerateInterpolator()); //and this
fadeOut.setStartOffset(1000);
fadeOut.setDuration(1500); //time in milliseconds

AnimationSet animation = new AnimationSet(false); //change to false
animation.addAnimation(fadeIn);
animation.addAnimation(fadeOut);
this.setAnimation(animation);

代码示例来源:origin: ankidroid/Anki-Android

public static Animation fade(int type, int duration, int offset) {
    float startValue = type;
    Animation animation = new AlphaAnimation(startValue, 1.0f - startValue);
    animation.setDuration(duration);
    if (type == FADE_IN) {
      animation.setZAdjustment(Animation.ZORDER_TOP);
    }
    animation.setStartOffset(offset);
    return animation;
  }
}

代码示例来源:origin: dinuscxj/RecyclerRefreshLayout

private void initAnimation() {
  mRotateAnimation = new RotateAnimation(0, -180, Animation.RELATIVE_TO_SELF, 0.5f,
      Animation.RELATIVE_TO_SELF, 0.5f);
  mRotateAnimation.setInterpolator(ANIMATION_INTERPOLATOR);
  mRotateAnimation.setDuration(ANIMATION_DURATION);
  mRotateAnimation.setFillAfter(true);
  mResetRotateAnimation = new RotateAnimation(-180, 0, Animation.RELATIVE_TO_SELF, 0.5f,
      Animation.RELATIVE_TO_SELF, 0.5f);
  mResetRotateAnimation.setInterpolator(ANIMATION_INTERPOLATOR);
  mResetRotateAnimation.setDuration(ANIMATION_DURATION);
  mResetRotateAnimation.setFillAfter(true);
}

代码示例来源:origin: stackoverflow.com

Animation animation = new AlphaAnimation(1, 0); // Change alpha
// from fully
// visible to
// invisible
animation.setDuration(500); // duration - half a second
animation.setInterpolator(new LinearInterpolator()); // do not alter
// animation
// rate
animation.setRepeatCount(Animation.INFINITE); // Repeat animation
// infinitely
animation.setRepeatMode(Animation.REVERSE); // Reverse animation at

// the
// end so the layout will
// fade back in
relativeLayout.startAnimation(animation);

相关文章

微信公众号

最新文章

更多