0

画像に触れる場所に赤い円を配置し、タッチをリッスンして座標を他のクラスに送信するクラスを作成したいと考えています。

public class Report extends Fragment {
private Context activity;
private Point point = new Point();
private DrawingCrl imgCircle = new DrawingCrl();

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.report, container,
            false);
    activity = this.getActivity();

            //Where I'm doing the touching and respond to that:
    final View touchView = rootView.findViewById(R.id.ImageC);
    touchView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            point.x = Float.valueOf(event.getX());
            point.y = Float.valueOf(event.getY());
                            touchView = imgCircle.DrawCircle(Point point);
            return true;
        }
    });

    return rootView;

    public class Point {
        float x;
        float y;
}

}

DrawCircle を呼び出すと、DrawingCrl クラスにそれを実行させたいので、メソッドに送信したポイントに円を描画します。

public class DrawingCrl {
private Bitmap mBitmap;
private Paint paint;
    private Canvas canvas = new Canvas();

public void DrawCircle(Point point) {
    mBitmap = Bitmap.createBitmap(400, 800, Bitmap.Config.ARGB_8888);
    paint = new Paint();
    paint.setColor(Color.RED);
    paint.setStyle(Style.FILL);
    canvas.drawCircle(point.x, point.y, 50, paint);
}
}

X 座標と Y 座標の取得と円描画とタッチでの円の描画の両方を読みましたが、円の描画方法がわかりません。

私はアンドロイドにかなり慣れていないので、多くの初心者の失敗を申し訳ありません。これを機能させるのを手伝ってくれることを願っています! ありがとう!:)

4

1 に答える 1