Android: ¿Cómo mover un BitmapDrawable?
Estoy tratando de mover unaBitmapDrawable
en una vista personalizada. Funciona bien con unaShapeDrawable
como sigue
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();
}
}
Sin embargo, si uso unBitmapDrawable
, los límites del dibujo cambian, laonDraw
e llama al método @, pero la imagen permanece donde está en la pantalla.
El siguiente constructor reproducirá el problema creando un BitmapDrawable en su lugar:
public MyView() {
image = getResources().getDrawable(R.drawable.image);
image.setBounds(0, 0, 100, 100);
}
¿Cómo puedo mover unBitmapDrawable
?