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);
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; } }
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);
TextView myText = (TextView) findViewById(R.id.myText ); Animation anim = new AlphaAnimation(0.0f, 1.0f); anim.setDuration(50); //You can manage the blinking time with this parameter anim.setStartOffset(20); anim.setRepeatMode(Animation.REVERSE); anim.setRepeatCount(Animation.INFINITE); myText.startAnimation(anim);
TextView myText = (TextView) findViewById(R.id.myText ); Animation anim = new AlphaAnimation(0.0f, 1.0f); anim.setDuration(50); //You can manage the time of the blink with this parameter anim.setStartOffset(20); anim.setRepeatMode(Animation.REVERSE); anim.setRepeatCount(Animation.INFINITE); myText.startAnimation(anim);
@Override public boolean onPreDraw() { mPopup.getContentView().getViewTreeObserver().removeOnPreDrawListener(this); for(int i = 0, count = mDropDownList.getChildCount(); i < count; i ++){ View v = mDropDownList.getChildAt(i); Animation anim = AnimationUtils.loadAnimation(mContext, mItemAnimationId); anim.setStartOffset(mItemAnimationOffset * i); v.startAnimation(anim); } return false; }
animation.setStartOffset(offset); return animation;
fadeOut.setStartOffset(fadeInDuration + timeBetween); fadeOut.setDuration(fadeOutDuration);
/** * Starts a Flashing Animation on the AwesomeTextView * * @param forever whether the animation should be infinite or play once * @param speed how fast the item should flash */ public void startFlashing(boolean forever, AnimationSpeed speed) { Animation fadeIn = new AlphaAnimation(0, 1); //set up extra variables fadeIn.setDuration(50); fadeIn.setRepeatMode(Animation.REVERSE); //default repeat count is 0, however if user wants, set it up to be infinite fadeIn.setRepeatCount(0); if (forever) { fadeIn.setRepeatCount(Animation.INFINITE); } fadeIn.setStartOffset(speed.getFlashDuration()); startAnimation(fadeIn); }
/** * Starts a rotating animation on the AwesomeTextView * * @param clockwise true for clockwise, false for anti clockwise spinning * @param speed how fast the item should rotate */ public void startRotate(boolean clockwise, AnimationSpeed speed) { Animation rotate; //set up the rotation animation if (clockwise) { rotate = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); } else { rotate = new RotateAnimation(360, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); } //set up some extra variables rotate.setRepeatCount(Animation.INFINITE); rotate.setInterpolator(new LinearInterpolator()); rotate.setStartOffset(0); rotate.setRepeatMode(Animation.RESTART); rotate.setDuration(speed.getRotateDuration()); startAnimation(rotate); }
@Test @Ignore("Needs additional work") public void start_shouldRunAnimation() { final AnimationSet set = new AnimationSet(true); final Animation move = new TranslateAnimation(0, 100, 0, 100); move.setDuration(1000); move.setAnimationListener(moveListener); final Animation spin = new RotateAnimation(0, 360); spin.setDuration(1000); spin.setStartOffset(1000); spin.setAnimationListener(spinListener); set.start(); verify(moveListener).onAnimationStart(move); Robolectric.flushForegroundThreadScheduler(); verify(moveListener).onAnimationEnd(move); } }
Animation animation = AnimationUtils.loadAnimation(getBaseContext(), R.anim.slide_right_in); animation.setStartOffset(0); myButton.startAnimation(animation);
public Animation PlayAnim( int viewid, Context Con, int animationid, int StartOffset ) { View v = findViewById(viewid); if( v != null ) { Animation animation = AnimationUtils.loadAnimation(Con, animationid ); animation.setStartOffset(StartOffset); v.startAnimation(animation); return animation; } return null; }
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);
fadeOut.setStartOffset(fadeInDuration + timeBetween); fadeOut.setDuration(fadeOutDuration);
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); View.startAnimation(animation);
Handler handler = new Handler(); Animation fadeIn = new AlphaAnimation(0, 1); fadeIn.setInterpolator(new DecelerateInterpolator()); //add this fadeIn.setDuration(2000); 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); logo.setAnimation(animation);
LinearLayout ll = (LinearLayout) findViewById(R.id.activity_main); Animation anim = new AlphaAnimation(0.0f, 1.0f); anim.setDuration(50); anim.setStartOffset(20); anim.setRepeatMode(Animation.REVERSE); anim.setRepeatCount(Animation.INFINITE); ll.startAnimation(anim);
Animation fadeIn = new AlphaAnimation(0, 1); fadeIn.setDuration(1000); Animation fadeOut = new AlphaAnimation(1, 0); fadeOut.setStartOffset(1000); fadeOut.setDuration(1000); AnimationSet animation = new AnimationSet(true); animation.addAnimation(fadeIn); animation.addAnimation(fadeOut); view.startAnimation(animation);
private void initInAnimation(@IntRange(from = 0) long duration) { if (getInAnimation() == null) this.setInAnimation(getContext(), R.anim.grow_from_middle_x_axis); super.getInAnimation().setDuration(duration); super.getInAnimation().setStartOffset(anticipateInAnimationTime > duration ? duration : duration - anticipateInAnimationTime); }