ホームに戻る
 描画

package org.example.test;

import android.app.*;
import android.content.*;
import android.graphics.*;
import android.os.*;
import android.view.*;
import android.widget.*;

public class Draw extends Activity
{
    private int width;
    private int height;
    private SampleView sv;

    public void onCreate(Bundle savedInstanceState)
    {
      super.onCreate(savedInstanceState);

      WindowManager wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
      Display disp = wm.getDefaultDisplay();
      width = disp.getWidth();
      height = disp.getHeight();

      LinearLayout ll = new LinearLayout(this);
      ll.setOrientation(LinearLayout.VERTICAL);
      setContentView(ll);

      sv = new SampleView(this);

      ll.addView(sv);
    }

    class SampleView extends View
    {
      private float x, y;

      public SampleView(Context cn)
      {
        super(cn);

        x = width / 2;
        y = height / 2;
      }

      public boolean onTouchEvent(MotionEvent e)
      {
        x = e.getX();
        y = e.getY();

        this.invalidate();

        return true;
      }

      protected void onDraw(Canvas cv)
      {
        super.onDraw(cv);

        Paint p = new Paint();
        p.setColor(Color.argb(255,255,0,0));
        cv.drawPoint(x, y - 5, p);
        cv.drawPoint(x - 5, y, p);
        cv.drawPoint(x, y, p);
        cv.drawPoint(x + 5, y, p);
        cv.drawPoint(x, y + 5, p);
      }
    }
}

inserted by FC2 system