gpt4 book ai didi

Android : Display coordinates x, y 触摸时使用 drawtext

转载 作者:行者123 更新时间:2023-11-29 14:05:14 24 4
gpt4 key购买 nike

我想通过ontouch事件显示放置在 View 上的节点坐标,坐标将放置在圆形节点旁边,暂时我正在使用(0,0)但我不知道如何正确实现节点上的真实坐标,需要一些帮助。谢谢

public class DrawView extends View implements OnTouchListener {
List<Point> points = new ArrayList<Point>();
Paint paint = new Paint();

public DrawView(Draw context) {
super(context);
setFocusable(true);
setFocusableInTouchMode(true);
this.setOnTouchListener(this);
paint.setColor(Color.RED);
paint.setAntiAlias(true);

}
@Override
public void onDraw(Canvas canvas) {
Paint rectanglePaint = new Paint();
rectanglePaint.setColor(Color.WHITE);
Paint layoutColor = new Paint();
layoutColor.setColor(Color.BLACK);
canvas.drawRect(new Rect(10,10,465,800), rectanglePaint);
canvas.drawLine(300, 10, 300, 800, layoutColor);
canvas.drawLine(0, 300, 465, 300, layoutColor);


// Paint textPaint = new Paint();
// textPaint.setColor(Color.CYAN);
// textPaint.setTextSize(30);
// canvas.drawText("Room", 220, 400, textPaint);




for (Point point : points) {


canvas.drawText("(0,0)", point.x+5, point.y+5, paint);
canvas.drawCircle(point.x, point.y, 5, paint);
// Log.d(TAG, "Painting: "+point);
}
}
final TextView textView = ( TextView )findViewById(R.id.textView1);
public boolean onTouch(View view, MotionEvent event) {
// return super.onTouchEvent(event);
Point point = new Point();
point.x = event.getX();
point.y = event.getY();
points.add(point);
invalidate();



return true;
}

最佳答案

啊,你真的没有关于 android 的问题。你有一个java问题。您想知道如何将 float 转换为字符串。

此链接将向您展示您需要了解的所有信息:http://download.oracle.com/javase/tutorial/java/data/converting.html

String s = "(" + point.x + "," + point.y + ")";

关于Android : Display coordinates x, y 触摸时使用 drawtext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7396271/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com