ontouchevent - Android stops sending onTouch events -
I have a custom view for which I want to handle touch events. In particular, its content should be scrolled by dragging a finger on the scene. To do this, I have implemented the following Touch Listener:
Private on-touch listener graph on-touch listener = new on-touch listener (public) Boolean on-touch (view, Motion Avent Event) {System.out.println (""); System.out.println ("View Width:" + v.getWidth ()); System.out.println ("see the height:" + v.getHeight ()); System.out.println ("View:" + V); Switch (event.getAction () and MotionEvent.ACTION_MASK) {Case MotionEvent.ACTION_DOWN: // First Finger System. Out.printline ("ACTION_DOWN x:" + event.getX () + ", y:" + Event Gety ()); StartTouch (event.getX ()); break; Case MotionEvent.ACTION_UP: // Final finger to displace the system. Print ("ACTION_UP x:" + event.getX () + ", y:" + event.getY ()); break; Case MotionEvent.ACTION_MOVE: // A finger moves System.out.println ("ACTION_MOVE x:" + event.getX () + ", y:" + event.getY ()); MoveTouch (event.getX ()); break; Default: Break; } // This event has been handled, so the true return is correct; }}; This works as expected, as long as the user does not take his finger up or down on the scene. At this point, prevent the event from touching (due to the lack of output in the logkat). However, using the adb shell getevent still shows events caused by the touch movement. Can someone suggest how I can improve it?
According to the request, layout XML looks like this:
& lt ;? Xml version = "1.0" encoding = "utf-8" & gt; & Lt; LinearLayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" android: orientation = "vertical" Android: background = "#ffffff "& Gt; & Lt; FrameLayout Android: layout_width = "fill_parent" android: layout_height = "fill_parent" & gt; & Lt; ScrollView Android: layout_width = "fill_parent" android: layout_height = "fill_parent" android: padding = "10dip" & gt; & Lt; LinearLayout Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" android: orientation = "vertical" & gt; & Lt; Com.graphlib.ShaderAreaGraphViewAndroid: layout_width = "fill_parent" android: layout_height = "200dip" Android: id = "@ + id / activity_power_realtime" Android: background = "# 000000" /> & Lt; LinearLayout Android: layout_width = "fill_parent" android: id = "@ + id / linearLayout1" Android: layout_height = "wrap_content" Android: gravity = "center" & gt; & Lt; Button Android: text = "& lt; & lt;" Android: ID = "@ + ID / BackBeerButton" Android: layout_width = "wrap-content" Android: layout_heat = "wrap-content" & gt; & Lt; / Button & gt; & Lt; Button Android: Text = "Zoom Out" Android: id = "@ + id / zoomOutButton" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" & gt; & Lt; / Button & gt; & Lt; Button Android: text = "zoom in" Android: id = "@ + id / zoom inbutton" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" & gt; & Lt; / Button & gt; & Lt; Button Android: text = "& amp; gt; & amp; gt;" Android: Android: Android: Android: Android: Android: Android: Android: Android: Android: Android: Android: ID = & lt; / LinearLayout & gt; & gt; LinearLayout & gt; & Lt; ; / Scrollview>
You need to write in each case when it breaks. Otherwise every case is executed.
Case MotionEvent.ACTION_DOWN: // First finger system.out.printeline ( "ACTION_DOWN x:" + event.getX () + ", y:" + event.getY ()); startTouch (event.getX ()); breakdown; MotionEvent.ACTION_UP: // Final finger to deplete the system. Print. ("ACTION_UP x:" + event.getX () + ", y:" + event.getY ()); breakage; MotionEvent.ACTION_MOVE: // A finger moves System.out.println ("ACTION_MOVE x: "+ Event.getX () +", y: "+ event.getY ()); moveTouch (event.getX ()); breakdown; or if you ... and If the condition can be entered in
Comments
Post a Comment