Android achieves the non-scroll Effect of ListView. androidlistview

Source: Internet
Author: User

Android achieves the non-scroll Effect of ListView. androidlistview


The expected result is that the ListView cannot be rolled, but the biggest problem is that there must be a click event with the ListView Item. If you do not need to click the event, it is easy to set the ListView directly. setEnable (false );

If you still need to click events, the scrolling and clicking operations are all managed in the ListView Touch processing mechanism.

The processing logic of the ViewGroup is reused in the ListView click event. When a user clicks a view and the distance between the pressed and raised fingers is small, the click event will be triggered if the time limit of the clicked event is met.

The ListView rolling event is self-handled and has two judgment conditions. When the user triggers the move event and the sliding distance exceeds the touch slop distance or the sliding speed exceeds the threshold, the event is regarded as a rolling event.


Import android. content. context; import android. util. attributeSet; import android. view. motionEvent; import android. widget. listView; public class ScrollDisabledListView extends ListView {private int mPosition; public ScrollDisabledListView (Context context) {super (context);} public ScrollDisabledListView (Context context, AttributeSet attrs) {super (context, attrs);} public ScrollDisabledListView (Context context, AttributeSet attrs, int defStyle) {super (context, attrs, defStyle);} @ Override public boolean dispatchTouchEvent (MotionEvent ev) {final int actionMasked = ev. getActionMasked () & MotionEvent. ACTION_MASK; if (actionMasked = MotionEvent. ACTION_DOWN) {// records the position mPosition = pointToPosition (int) ev when the finger is pressed. getX (), (int) ev. getY (); return super. dispatchTouchEvent (ev);} if (actionMasked = MotionEvent. ACTION_MOVE) {// the most critical part. Ignore the MOVE event // The ListView onTouch will not be able to get the MOVE event, so it will not be rolled back and return true ;} // if (actionMasked = MotionEvent. ACTION_UP | actionMasked = MotionEvent. ACTION_CANCEL) {// press your finger and lift it in the same view and hand it over to the parent Control for processing. This is a click event if (pointToPosition (int) ev. getX (), (int) ev. getY () = mPosition) {super. dispatchTouchEvent (ev);} else {// If the finger has been removed from the Item when it is pressed, it indicates a rolling action. The setPressed (false) state of the Item is cleared; invalidate (); return true;} return super. dispatchTouchEvent (ev );}}

References:

Disable scrolling in Android ListView


Disable scrolling in listview

Reprinted please indicate the source:

ListView cannot be rolled in Android settings

Http://blog.csdn.net/androiddevelop/article/details/38815493





In android, how does one make its entry content scroll? Use animation? Or other methods?

What is ScrollView in xml layout! I also forgot ···

In android, how does one disable the built-in scrolling Effect of listview?

Set listview to a height?

Related Article

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.