Android view can only receive Action_down cannot receive Action_move and ACTION_UP solution

Source: Internet
Author: User

Last night debugging a night, on the LinearLayout to receive screen action, but there is a problem, the following code is the code I tuned

</pre><pre name= "code" class= "java" >private int pressedarrow;public class Onsettertouchlistener Implements Ontouchlistener {@Overridepublic Boolean onTouch (View V, motionevent event) {Float pt = event.getx (); switch (EV Ent.getaction ()) {Case MotionEvent.ACTION_DOWN:if (pt > Last_strpos && pt < Last_endpos) {if (PT-LAST_STRP OS <= last_endpos-pt) {cur_strpos = Pt;pressedarrow = R.id.start_pos;} else {cur_endpos = Pt;pressedarrow = R.id.end_ POS;}}  else if (PT <= last_strpos) {cur_strpos = Pt;pressedarrow = R.id.start_pos;} else if (pt >= last_endpos) {Cur_endpos = Pt;pressedarrow = R.id.end_pos;} Requestlayout (); LOG.D (TAG, "down" + Cur_strpos + "" + cur_endpos); last_endpos = Cur_endpos;last_strpos = Cur_strpos;break;case MotionEve Nt. ACTION_MOVE:LOG.D (TAG, "MOVE" + Cur_strpos + "" + Cur_endpos); if (Pressedarrow = = R.id.start_pos) {if (pt < LAST_ENDP OS) Cur_strpos = pt;} else if (Pressedarrow = = R.id.end_pos) {if (pt > Last_strpos) cur_endpos = pt;} Requestlayout (); last_endpos = Cur_endpos;last_strpos = Cur_strpos;break;case MotionEvent.ACTION_UP:updateCalibrator (int) cur_strpos); break;} return false;}}

Such a look at this ontouchlistener should be no problem. A return of false at the end indicates that the event has been consumed here. But open Ddms to view the print log. When the finger is sliding to the imageview of the above touch listener, it is always printed action_move here, very obviously not at all. Later, all kinds of search problems can not be found. Because the Action_down is able to enter. But Action_move and action_up are not, it is not the problem of the code.


A variety of search only found that the settings to listen to the view of the properties set to Android:clickable= "true" so talented enough to respond to Action_move and action_up.

        <imageview            android:id= "@+id/track"            android:layout_width= "match_parent"            android:layout_height= " 20DP "            android:clickable=" true "            android:layout_gravity=" center "            android:background=" #00000000 "            Android:baselinealignbottom= "true"            android:visibility= "visible"/>


It's down here. also provides a convenient for others


View in Android can only receive a method that Action_down cannot receive action_move and ACTION_UP resolution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.