我正在尝试将我创建的矩形移动到屏幕的中心,因为我正在使用加速计允许它移动,有没有办法将形状移动到屏幕的中心而不使用android xml?
public class CustomDrawableView extends View
{
static final int width = 150;
static final int height = 250;
public CustomDrawableView(Context context)
{
super(context);
mDrawable = new ShapeDrawable(new RectShape());
mDrawable.getPaint().setColor(0xff74AC23);
mDrawable.setBounds(x, y, x + width, y + height);
}
protected void onDraw(Canvas canvas)
{
RectF rect = new RectF(AccelActivity.x, AccelActivity.y, AccelActivity.x + width, AccelActivity.y
+ height); // set bounds of rectangle
Paint p = new Paint(); // set some paint options
p.setColor(Color.BLUE);
canvas.drawRect(rect, p);
invalidate();
}
}
}
答案 0 :(得分:0)
是的,请查看此示例,在那里不使用xml:How can I use the animation framework inside the canvas?
使用sizeChanged查找画布的实际大小......