2012-02-08 4 views
1

私は加速度計を使って画面の中心に移動して矩形を移動しようとしていますが、Androidのxmlを使用せずに画面の中央に移動する方法はありますか?onDrawメソッドで作成した図形を画面上の中央に移動するにはどうすればいいですか?

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(); 

     } 
    } 
} 

答えて

関連する問題