Android Development's Custom dropdown flush head

Source: Internet
Author: User
Tags flush

Always use the Drop-down Refresh Library is Android-ultra-pull-to-refresh, itself this library with several styles of Drop-down refresh head, you can go git look, address https://github.com/liaohuqiu/ Android-ultra-pull-to-refresh. The most convenient is that we can customize all kinds of head. The recent project has a custom Drop-down head, which I studied for myself. The implementation effect is:

All we have to do is write a style XML file of our own, and then implement Ptruihandler this interface with the following code:


public class Loadmorefooterview extends Framelayout implements Ptruihandler {
Private Layoutinflater Inflater;

Drop-down Refresh view (header View)
Private ViewGroup Headview;

Drop Refresh Text
Private TextView Tvheadtitle;

Drop down icon
Private ImageView Ivwindmill;

Private Windmilldrawable drawable;

Public Loadmorefooterview {
This is (context, NULL);
}

Public Loadmorefooterview (context context, AttributeSet Attrs) {
This is (context, attrs, 0);
}

Public Loadmorefooterview (context context, AttributeSet attrs, int defstyleattr) {
Super (context, attrs, defstyleattr);
Init (context);
}

/**
* Initialization
*
* @param context
*/
private void init (context context) {

Inflater = Layoutinflater.from (context);
/**
* Head
*/
Headview = (viewgroup) inflater.inflate (R.layout.widget_header, this, true);
Ivwindmill = (ImageView) Headview.findviewbyid (R.id.iv_windmill);
Tvheadtitle = (TextView) Headview.findviewbyid (r.id.tv_head_title);
Ivwindmill.setvisibility (VISIBLE);
Ivwindmill.setimageresource (R.mipmap.icon_logo);
Tvheadtitle.settext ("Drop-down refresh");

}

@Override
public void Onuireset (Ptrframelayout ptrframelayout) {
Tvheadtitle.settext ("Drop-down refresh");

}

@Override
public void Onuirefreshprepare (Ptrframelayout ptrframelayout) {
Tvheadtitle.settext ("Drop-down refresh");
}

@Override
public void Onuirefreshbegin (Ptrframelayout ptrframelayout) {
Tvheadtitle.settext ("refreshing");

}

@Override
public void Onuirefreshcomplete (Ptrframelayout ptrframelayout) {
Ivwindmill.clearanimation ();
Tvheadtitle.settext ("Refresh complete");
}

@Override
public void Onuipositionchange (Ptrframelayout frame, Boolean isundertouch, byte status, Ptrindicator ptrindicator) {
Final int moffsettorefresh = Frame.getoffsettorefresh ();
Final int currentpos = Ptrindicator.getcurrentposy ();
Final int lastpos = Ptrindicator.getlastposy ();

if (currentpos < moffsettorefresh && lastpos >= moffsettorefresh) {
if (isundertouch && status = Ptrframelayout.ptr_status_prepare) {
Tvheadtitle.settext ("Drop-down refresh");
}
else if (currentpos > moffsettorefresh && lastpos <= moffsettorefresh) {
if (isundertouch && status = Ptrframelayout.ptr_status_prepare) {
Tvheadtitle.settext ("loosen refresh");
}
}

}

}


Use:

/* Create custom Refresh head View/*
Loadmorefooterview Header = new Loadmorefooterview (this);
/* Set Refresh head View * *
Ptr_view.setheaderview (header);
/* Set callback/*
Ptr_view.addptruihandler (header);
Ptr_view.setptrhandler (New Ptrhandler () {
@Override
public boolean Checkcandorefresh (ptrframelayout frame, view content, view header) {
Return Ptrdefaulthandler.checkcontentcanbepulleddown (frame, content, header);
}

@Override
public void Onrefreshbegin (Ptrframelayout frame) {
Ptr_view.postdelayed (New Runnable () {
@Override
public void Run () {

GetData ();
}
}, 2000);
}
});
/* Delay 100 seconds, automatic refresh * *
Ptr_view.postdelayed (New Runnable () {
@Override
public void Run () {
Ptr_view.autorefresh ();
}
}, 100);

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.