本文整理汇总了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();
}
}