@Override protected void onPostExecute(Drawable result) { if (result != null) { if (albumArt.getDrawable() != null) { final TransitionDrawable td = new TransitionDrawable(new Drawable[]{ albumArt.getDrawable(), result }); albumArt.setImageDrawable(td); td.startTransition(200); } else { albumArt.setImageDrawable(result); } } }
private void setDrawable(Drawable result) { if (result != null) { if (mBackAlbum.getDrawable() != null) { final TransitionDrawable td = new TransitionDrawable(new Drawable[]{mBackAlbum.getDrawable(), result}); mBackAlbum.setImageDrawable(td); //去除过度绘制 td.setCrossFadeEnabled(true); td.startTransition(200); } else { mBackAlbum.setImageDrawable(result); } } }
TransitionDrawable transitionDrawable = new TransitionDrawable(drawables); if (((RadioButton) view).isChecked()) { transitionDrawable.reverseTransition(0);
public static void startSwitchBackgroundAnim(ImageView view, Bitmap bitmap) { Drawable oldDrawable = view.getDrawable(); Drawable oldBitmapDrawable ; TransitionDrawable oldTransitionDrawable = null; if (oldDrawable instanceof TransitionDrawable) { oldTransitionDrawable = (TransitionDrawable) oldDrawable; oldBitmapDrawable = oldTransitionDrawable.findDrawableByLayerId(oldTransitionDrawable.getId(1)); } else if (oldDrawable instanceof BitmapDrawable) { oldBitmapDrawable = oldDrawable; } else { oldBitmapDrawable = new ColorDrawable(0xffc2c2c2); } if (oldTransitionDrawable == null) { oldTransitionDrawable = new TransitionDrawable(new Drawable[]{oldBitmapDrawable, new BitmapDrawable(bitmap)}); oldTransitionDrawable.setId(0, 0); oldTransitionDrawable.setId(1, 1); oldTransitionDrawable.setCrossFadeEnabled(true); view.setImageDrawable(oldTransitionDrawable); } else { oldTransitionDrawable.setDrawableByLayerId(oldTransitionDrawable.getId(0), oldBitmapDrawable); oldTransitionDrawable.setDrawableByLayerId(oldTransitionDrawable.getId(1), new BitmapDrawable(bitmap)); } oldTransitionDrawable.startTransition(1000); } }
public void setSync(boolean sync) { if(sync != this.sync) { if(sync) drawable.startTransition(TRANSITION_DURATION); else drawable.reverseTransition(TRANSITION_DURATION); this.sync = sync; } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TransitionDrawable transition = (TransitionDrawable) getResources() .getDrawable(R.drawable.shape_transition,null); transition.setCrossFadeEnabled(true); ((ImageView) findViewById(R.id.image_view)).setImageDrawable(transition); transition.startTransition(5000); } }
TransitionDrawable transition = (TransitionDrawable) viewObj.getBackground(); transition.startTransition(transitionTime);
if (d != null && d instanceof TransitionDrawable) { if (longClickable) { ((TransitionDrawable) d).startTransition(longPressTimeout); } else { ((TransitionDrawable) d).resetTransition();
void setIsDragOverlapping(boolean isDragOverlapping) { if (mIsDragOverlapping != isDragOverlapping) { mIsDragOverlapping = isDragOverlapping; if (mIsDragOverlapping) { mBackground.startTransition(BACKGROUND_ACTIVATE_DURATION); } else { if (mBackgroundAlpha > 0f) { mBackground.reverseTransition(BACKGROUND_ACTIVATE_DURATION); } else { mBackground.resetTransition(); } } invalidate(); } }
try { // Transition drawable with a transparent drawable and the final bitmap TransitionDrawable td = new TransitionDrawable(new Drawable[] { aImageView.getDrawable(), aResult }); td.setCrossFadeEnabled(true); td.setBounds(new Rect(0, 0, aImageView.getWidth(), aImageView.getHeight())); ImageView.ScaleType scaleType = aImageView.getScaleType(); aImageView.setImageDrawable(td); aImageView.setScaleType(scaleType); td.startTransition(mFadeInTime); } catch (StackOverflowError e) {}
@Test public void onFrameReady_whenAttachedtoDrawableCallbackWithViewCallbackParent_doesNotStop() { TransitionDrawable topLevel = new TransitionDrawable(new Drawable[] { drawable }); drawable.setCallback(topLevel); topLevel.setCallback(new View(context)); drawable.start(); drawable.onFrameReady(); assertThat(drawable.isRunning()).isTrue(); }
private void setIconAnimation(Drawable icon, Drawable endIcon){ drawables[0] = icon; drawables[1] = endIcon; crossfader = new TransitionDrawable(drawables); crossfader.setCrossFadeEnabled(true); setImageDrawable(crossfader); }
TransitionDrawable drawable = (TransitionDrawable) mPlayBtn.getDrawable(); drawable.setCrossFadeEnabled(true);
@Override protected TransitionDrawable doInBackground(Void... params) { Bitmap bitmap = Utils.scaleDown(R.drawable.background, Utils.screenWidth(), Utils.screenHeight()); Bitmap backgroundImage = Themes.getBackgroundImage(mSelectedTheme); backgroundImage = Utils.crop(backgroundImage, Utils.screenHeight(), Utils.screenWidth()); Drawable backgrounds[] = new Drawable[2]; backgrounds[0] = new BitmapDrawable(Shared.context.getResources(), bitmap); backgrounds[1] = new BitmapDrawable(Shared.context.getResources(), backgroundImage); TransitionDrawable crossfader = new TransitionDrawable(backgrounds); return crossfader; }
Drawable d = mSelector.getCurrent(); if (d != null && d instanceof TransitionDrawable) { ((TransitionDrawable) d).resetTransition();
@Override public void onCheckedChanged(RadioGroup group, int checkedId) { TransitionDrawable current = mDrawableMap.get(checkedId); current.reverseTransition(200); if (mLastCheckId != 0) { TransitionDrawable last = mDrawableMap.get(mLastCheckId); if (last != null) last.reverseTransition(200); } mLastCheckId = checkedId; if (mCheckedChangeListener != null) { mCheckedChangeListener.onCheckedChanged(group, checkedId); } } });
TransitionDrawable transition = (TransitionDrawable) viewObj.getBackground(); transition.startTransition(transitionTime); Or run the transition in reverse by calling: transition.reverseTransition(transitionTime);
transitionDrawable.setCrossFadeEnabled(false); transitionDrawable.startTransition(duration);
public static void startSwitchBackgroundAnim(ImageView view, Bitmap bitmap) { Drawable oldDrawable = view.getDrawable(); Drawable oldBitmapDrawable ; TransitionDrawable oldTransitionDrawable = null; if (oldDrawable instanceof TransitionDrawable) { oldTransitionDrawable = (TransitionDrawable) oldDrawable; oldBitmapDrawable = oldTransitionDrawable.findDrawableByLayerId(oldTransitionDrawable.getId(1)); } else if (oldDrawable instanceof BitmapDrawable) { oldBitmapDrawable = oldDrawable; } else { oldBitmapDrawable = new ColorDrawable(0xffc2c2c2); } if (oldTransitionDrawable == null) { oldTransitionDrawable = new TransitionDrawable(new Drawable[]{oldBitmapDrawable, new BitmapDrawable(bitmap)}); oldTransitionDrawable.setId(0, 0); oldTransitionDrawable.setId(1, 1); oldTransitionDrawable.setCrossFadeEnabled(true); view.setImageDrawable(oldTransitionDrawable); } else { oldTransitionDrawable.setDrawableByLayerId(oldTransitionDrawable.getId(0), oldBitmapDrawable); oldTransitionDrawable.setDrawableByLayerId(oldTransitionDrawable.getId(1), new BitmapDrawable(bitmap)); } oldTransitionDrawable.startTransition(1000); } }
final TransitionDrawable background = (TransitionDrawable) view.getBackground(); background.startTransition(300);