Спасибо, copyBounds и setBounds сделали свое дело!
аюсь переместитьBitmapDrawable
в пользовательском представлении. Работает нормально сShapeDrawable
следующее:
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();
}
}
Однако, если я используюBitmapDrawable
, границы рисования меняются,onDraw
метод вызывается, но изображение остается там, где оно находится на экране.
Следующий конструктор воспроизведет проблему, создав вместо этого BitmapDrawable:
public MyView() {
image = getResources().getDrawable(R.drawable.image);
image.setBounds(0, 0, 100, 100);
}
Как я могу переместитьBitmapDrawable
?