本文整理匯總了Java中android.graphics.drawable.TransitionDrawable.getNumberOfLayers方法的典型用法代碼示例。如果您正苦於以下問題:Java TransitionDrawable.getNumberOfLayers方法的具體用法?Java TransitionDrawable.getNumberOfLayers怎麽用?Java TransitionDrawable.getNumberOfLayers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.drawable.TransitionDrawable
的用法示例。
在下文中一共展示了TransitionDrawable.getNumberOfLayers方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onDraw
import android.graphics.drawable.TransitionDrawable; //導入方法依賴的package包/類
@Override
public void onDraw(Canvas canvas) {
Drawable drawable = this.getDrawable();
if(drawable != null) {
if(drawable instanceof BitmapDrawable) {
if (isBitmapRecycled(drawable)) {
this.setImageDrawable(null);
setInvalidated(true);
}
} else if(drawable instanceof TransitionDrawable) {
TransitionDrawable transitionDrawable = (TransitionDrawable) drawable;
// If last bitmap in chain is recycled, just blank this out since it would be invalid anyways
Drawable lastDrawable = transitionDrawable.getDrawable(transitionDrawable.getNumberOfLayers() - 1);
if(isBitmapRecycled(lastDrawable)) {
this.setImageDrawable(null);
setInvalidated(true);
} else {
// Go through earlier bitmaps and make sure that they are not recycled
for (int i = 0; i < transitionDrawable.getNumberOfLayers(); i++) {
Drawable layerDrawable = transitionDrawable.getDrawable(i);
if (isBitmapRecycled(layerDrawable)) {
// If anything in the chain is broken, just get rid of transition and go to last drawable
this.setImageDrawable(lastDrawable);
break;
}
}
}
}
}
super.onDraw(canvas);
}
示例2: removeDrawableAndHolder
import android.graphics.drawable.TransitionDrawable; //導入方法依賴的package包/類
private void removeDrawableAndHolder() {
// Remove drawable
Drawable drawable = getDrawable();
if (drawable instanceof TransitionDrawable) {
TransitionDrawable tDrawable = (TransitionDrawable) drawable;
int number = tDrawable.getNumberOfLayers();
if (number > 0) {
drawable = tDrawable.getDrawable(number - 1);
}
}
if (drawable instanceof ImageDrawable) {
((ImageDrawable) drawable).recycle();
}
setImageDrawable(null);
// Remove holder
if (mHolder != null) {
mHolder.release(this);
ImageWrapper imageWrapper = mHolder.getValue();
if (mHolder.isFree()) {
// ImageWrapper is free, stop animate
imageWrapper.stop();
if (!mHolder.isInMemoryCache()) {
// ImageWrapper is not needed any more, recycle it
imageWrapper.recycle();
}
}
mHolder = null;
}
}
示例3: start
import android.graphics.drawable.TransitionDrawable; //導入方法依賴的package包/類
public void start() {
Drawable drawable = getDrawable();
if (drawable instanceof TransitionDrawable) {
TransitionDrawable tDrawable = (TransitionDrawable) drawable;
int number = tDrawable.getNumberOfLayers();
if (number > 0) {
drawable = tDrawable.getDrawable(number - 1);
}
}
if (drawable instanceof ImageDrawable) {
((ImageDrawable) drawable).start();
}
}
示例4: stop
import android.graphics.drawable.TransitionDrawable; //導入方法依賴的package包/類
public void stop() {
Drawable drawable = getDrawable();
if (drawable instanceof TransitionDrawable) {
TransitionDrawable tDrawable = (TransitionDrawable) drawable;
int number = tDrawable.getNumberOfLayers();
if (number > 0) {
drawable = tDrawable.getDrawable(number - 1);
}
}
if (drawable instanceof ImageDrawable) {
((ImageDrawable) drawable).stop();
}
}