applibgroup / HarmonyOS-Knowledgebase

This repository contains code samples of HarmonyOS Training
Apache License 2.0
17 stars 6 forks source link

How to get the touch coordinates of a touch event in HarmonyOS? #8

Closed KomalKalyan closed 3 years ago

KomalKalyan commented 3 years ago

Describe the query

I am writing a helper class to zoom an image in HarmonyOS using Java SDK. I want to get the touch coordinates of the dispatched touch, in Android we can use the following code snippet.

MotionEvent.PointerCoords pointerCoords = new MotionEvent.PointerCoords(); 
event.getPointerCoords(index, pointerCoords); 

What is the alternative for the above in HarmonyOS?

Create the query with harmonyos tag in stackoverflow and share the link here:

https://stackoverflow.com/questions/68542512/how-to-get-the-touch-coordinates-of-a-touch-event-in-harmonyos

Additional information

Developer Platform: Windows DevEco Studio version: 2.1.0.303 SDK API version: 5 SDK version: 2.1.1.21 Device: Not Required Device OS version: Not Required

Regards, Komal Kalyan.

kanaksony commented 3 years ago

Looks like the answer is already replied to on StackOverflow. getPointerPosition() function from ManipulationEvent API should solve the purpose. Check the docs for the same.

https://developer.harmonyos.com/cn/docs/documentation/doc-references/manipulationevent-0000001054120214#ZH-CN_TOPIC_0000001054120214__getPointerPosition-int-

@KomalKalyan Please confirm else will close the issue assuming it answers your query.

kanaksony commented 3 years ago

Accepted on Stackoverflow, so good to close!