Detecting touch area on Android

前端 未结 3 1656
余生分开走
余生分开走 2021-01-05 21:56

Is it possible to detect every pixel being touched? More specifically, when the user touches the screen, is it possible to track all the x-y coordinates of the cluster of po

相关标签:
3条回答
  • 2021-01-05 22:16

    If you're looking for a way to get your content view as a View after Activity#setContentView(int), then you can set an id on the outer-most element of your layout:

    android:id="@+id/entire_view" and reference it in your onCreate() method after setContentView:

    View view = getViewById(R.id.entire_view);
    view.setOnTouchListener( ... );
    
    0 讨论(0)
  • 2021-01-05 22:19

    If you have a listener on your image it will respond that there was a touch within that bounding box, basically.

    So, to get what you want, you could, but, I would never do this, create a box around every pixel, or small group of pixels, and listen for a touch.

    Wherever you get a touch, it may fire off an event, then you can react accordingly.

    I can't think of any other solution that will give you each pixel that a person touched, at one time.

    You may want to read up on multitouch though, as there are some suggestions in here that my help you:

    http://android-developers.blogspot.com/2010/06/making-sense-of-multitouch.html

    0 讨论(0)
  • 2021-01-05 22:22

    This would be very tricky primarily because every android phone is going to behave differently. There are some touch screen devices that are very, very sensitive and some that are basically "dull" by comparison.

    It also sounds more like you are wanting to track pressure - how hard is the user pushing on the screen - which is actually supported on android devices.

    I think some of your answer may be found by monitoring all of the touch events - in practice, most applications ignore a great number of events or perform some kind of "smoothing" of the events since there is literally a deluge of touch events when the user is manipulating the screen. Doing this may negatively impact your applications performance though.

    I would recommend that you look into pressure sensitivity and calculate a circular region around the primary touch point based on pressure, then build your brush around that.

    Another idea would be to incorporate more of a gesture approach to what you are trying to do - for example, visualize touching the screen with the tip of two fingers together (index and middle) and rolling the middle finger around the index finger or simply moving the middle finger up and down in relation to the index finger. Both fingers would be moved together for painting. This could be used to manipulate drawing angle on the fly or perhaps even toggle between a set of pre-selected brushes or could change brush size on the fly as you are painting.

    Some of the above ideas I would love to see implemented - let me know when you have your app ready.

    Good luck! Rodney

    0 讨论(0)
提交回复
热议问题