How many times does ListView slide a page? Use the paging list !, Listview is uncomfortable

Source: Internet
Author: User

How many times does ListView slide a page? Use the paging list !, Listview is uncomfortable

Scrolling positions such as ListView often do not meet user expectations:

Most of the time I want to slide to the next page after reading a page, but it is difficult to control the sliding distance.

 

PageScroller is provided in the PagedListView project to solve this problem.

You can use PageScroller to scroll a page at moderate or low speed. If you slide slowly or quickly, the page is processed by default.

 

The usage is as follows:

1. initialize PageScroller

pageScroller = new PageScroller(lvListView);pageScroller.init();

 

2. Override the dispatchTouchEvent Method

In the dispatchTouchEvent method of the Activity, pageScroller. dispatchTouchEvent (ev );

@Overridepublic boolean dispatchTouchEvent(MotionEvent ev) {     pageScroller.dispatchTouchEvent(ev);     return super.dispatchTouchEvent(ev);}

 

 

 

The project also provides several demos, such as ListViewActivity.

1 package zuo. biao. pagedlistview; 2 3 import java. util. arrayList; 4 import java. util. list; 5 6 import android. app. activity; 7 import android. OS. bundle; 8 import android. view. motionEvent; 9 import android. widget. arrayAdapter; 10 import android. widget. listView; 11 12/** ListView example 13 * @ author Lemon14 */15 public class ListViewActivity extends Activity {16 17 private ListView lvListView; 18 private List <String> list; 19 private PageScroller pageScroller; 20 @ Override21 protected void onCreate (Bundle savedInstanceState) {22 super. onCreate (savedInstanceState); 23 setContentView (R. layout. list_view_activity); 24 25 lvListView = (ListView) findViewById (R. id. lvListView); 26 27 list = new ArrayList <String> (); 28 for (int I = 0; I <100; I ++) {29 list. add ("Item" + I); 30} 31 32 lvListView. setAdapter (new ArrayAdapter <String> (this, android. r. layout. simple_list_item_1, list); 33 34 pageScroller = new PageScroller (lvListView); 35 pageScroller. init (); 36} 37 38/** 39 * Fragment does not have this method. You can create a dispatchTouchEvent method in Fragment, 40 * And then override the dispatchTouchEvent method in the Activity that adds Fragment, and call the dispatchTouchEvent method in Fragment in this method, 41 * Is fragment. dispatchTouchEvent (ev); 42 */43 @ Override44 public boolean dispatchTouchEvent (MotionEvent ev) {45 pageScroller. dispatchTouchEvent (ev); 46 return super. dispatchTouchEvent (ev); 47} 48 49}

 

 

(Welcome to Star and Fork)

Https://github.com/TommyLemon/PagedListView

Download trial

PagedListView.apk

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.