AndroidPullToRefresh pull effect Configuration

Source: Internet
Author: User

Recently, the open-source AndroidPullToRefresh library was used, but it was found that the pull effect was quite strange. No matter how it was pulled up or down, when the list rolled to the top or bottom, the prompt of pulling the height of the half list will pop up instantly, Which is uncomfortable. This prompt is unnecessary, ugly, and may cause some strange small problems, so after checking the source code for a long time, I finally knew what was going on.

However, this library is still very famous, but there are almost no details about it on the Internet, and it is hard to find Chinese materials. Maybe you have not encountered many problems here ~~




My summary is as follows:

<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHByZSBjbGFzcz0 = "brush: java;">

1. Set two events:

In XML

ptr:ptrMode="both"

In Java

view.setMode(PullToRefreshBase.Mode.BOTH);

Register custom events pulled up and down

pullToRefreshListView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2
 
  () {    @Override    public void onPullUpToRefresh(PullToRefreshBase
  
    refreshView) {ZLog.i(TAG, "OnRefreshListener2 onPullUpToRefresh");diaryList.loadNext();    }    @Override    public void onPullDownToRefresh(PullToRefreshBase
   
     refreshView) {ZLog.i(TAG, "OnRefreshListener2 onPullDownToRefresh");refreshView.onRefreshComplete();    }});
   
  
 

PullToRefreshBase. OnRefreshListener2 is used here. () Interface

If there is only one direction, remove the 2 Characters and use PullToRefreshBase. OnRefreshListener. () Interface

Generally, some actions such as loading will be performed after the pull-down trigger event. When your logic processing is complete, you need to call back: onRefreshComplete (); method, indicating that the current event has completely ended, in this case, the pull loading prompt disappears.


Tip:

Note that if the pull effect of ListView is used, the layout will generate a dynamic ListView instance in the program instead of a ListView instance, to obtain a real ListView object, you must use a method to obtain it.

ListView listView = pullTorefreshView.getRefreshableView();


2. When you scroll to the top or bottom of the page, a prompt window is displayed to pull and load more data.

I think it is not very nice. There are two ways to solve this problem: Do not display | shorten the width of the height or horizontal

After reading the source code for half a day, I found out the specific function of the method. for foreigners, I can only see the method name and often cannot figure out what it is,

ptr:ptrOverScroll="false"

view.setPullToRefreshOverScrollEnabled(false);

The above is through the xml configuration and the configuration method in java. When it is set to false, the prompt will no longer pop up.


How to shorten the prompt box:

There is a constant setting in the library file PullToRefreshBase. java.



Code:

static final float FRICTION = 2.0f;

Here, 2.0f indicates that the height of the pop-up box is half of the height of the visible area on the screen, that is, screenHeight/2. It is proportional to each other. You can increase the value, if it is set to 5, it is a little more than 1/5 of the screen, but do not set it too large, resulting in a low height, which will affect the height of the prompt displayed during normal pull.



So much now. Please try again later ~~






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.