gpt4 book ai didi

java - 简单的 Drawable 装饰器不起作用

转载 作者:行者123 更新时间:2023-12-01 13:43:05 37 4
gpt4 key购买 nike

我正在一个 Activity 中执行此操作,其中 imageImageView:

Drawable d = getResources().getDrawable(R.drawable.somejpeg);

//only one of the lines below
image.setImageDrawable(d); //works
image.setImageDrawable(new DrawableDecorator(d)); //does not work - blank image

这是我的可绘制装饰器:

import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.drawable.Drawable;

public final class DrawableDecorator extends Drawable {

private final Drawable drawable;

public DrawableDecorator(Drawable drawable) {
this.drawable = drawable;
}

@Override
public void draw(Canvas canvas) {
drawable.draw(canvas);
}

@Override
public void setAlpha(int alpha) {
drawable.setAlpha(alpha);
}

@Override
public void setColorFilter(ColorFilter cf) {
drawable.setColorFilter(cf);
}

@Override
public int getOpacity() {
return drawable.getOpacity();
}

}

我已经覆盖了我必须做的事情,只是传递到装饰项目,但是我错过了什么导致失败?

请注意,调用了绘制方法。

最佳答案

我应该通过一些更重要的覆盖。

@Override
public boolean setVisible(boolean visible, boolean restart) {
return drawable.setVisible(visible, restart);
}

@Override
public void setBounds(int left, int top, int right, int bottom) {
drawable.setBounds(left, top, right, bottom);
}

@Override
public void setBounds(Rect bounds) {
drawable.setBounds(bounds);
}

@Override
public int getIntrinsicHeight() {
return drawable.getIntrinsicHeight();
}

@Override
public int getIntrinsicWidth() {
return drawable.getIntrinsicWidth();
}

关于java - 简单的 Drawable 装饰器不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20546214/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com