Android: Como mover um BitmapDrawable?
Estou tentando mover umBitmapDrawable
em uma exibição personalizada. Funciona bem com umShapeDrawable
do seguinte modo
public class MyView extends View {
private Drawable image;
public MyView() {
image = new ShapeDrawable(new RectShape());
image.setBounds(0, 0, 100, 100);
((ShapeDrawable) image).getPaint().setColor(Color.BLACK);
}
@Override
protected void onDraw(Canvas canvas) {
image.draw(canvas);
}
public void move(int x, int y) {
Rect bounds = image.getBounds();
bounds.left += x;
bounds.right += x;
bounds.top += y;
bounds.bottom += y;
invalidate();
}
}
No entanto, se eu usar umBitmapDrawable
, os limites do drawable mudam, oonDraw
método @ é chamado, mas a imagem permanece onde está na tel
O construtor a seguir reproduz o problema criando um BitmapDrawabl
public MyView() {
image = getResources().getDrawable(R.drawable.image);
image.setBounds(0, 0, 100, 100);
}
Como mover umBitmapDrawable
?