Guo Xiaoxing
Weibo: Guo Xiaoxing's Sina Weibo
Email:[email protected]
Blog: http://blog.csdn.net/allenwells
Github:https://github.com/allenwell
This article is the opening article of "User interface: Android-ultra-pull-to-refresh", which mainly introduces and shows the related functions of Android-ultra-pull-to-refresh, and introduces the relevant methods of integrating the framework in the project.
A feature introduction
Android-ultra-pull-to-refresh provides a technical framework for a drop-down refresh. Its main functions are as follows:
- Inherited from ViewGroup, content can contain any view.
- Concise and Perfect header abstraction, easy to expand, to build the head in line with the needs.
Two function show
Three-way use (1) Adding a dependent module
‘in.srain.cube:ultra-ptr:1.0.10‘
(2) Definition Ptrframelayout
There are two ways of defining Ptrframelayout:
- Define in a layout article
- Define in code
Define in a layout article
<inch. Srain. Cube. views. PTR. PtrframelayoutAndroid:id="@+id/store_house_ptr_frame"Xmlns:cube_ptr="Http://schemas.android.com/apk/res-auto"Android:layout_width="Match_parent"android:layout_height="Match_parent"Cube_ptr:ptr_resistance="1.7"Cube_ptr:ptr_ratio_of_header_height_to_refresh="1.2"Cube_ptr:ptr_duration_to_close="+"Cube_ptr:ptr_duration_to_close_header=" the"Cube_ptr:ptr_keep_header_when_refresh="true"Cube_ptr:ptr_pull_to_fresh="false"> <linearlayout android:id="@+id/store_house_ptr_image_content"Android:layout_width="Match_parent"android:layout_height="Match_parent"Android:background="@color/cube_mints_333333"android:clickable="true"android:padding="10DP"> <inch. Srain. Cube. Image. CubeimageviewAndroid:id="@+id/store_house_ptr_image"Android:layout_width="Match_parent"android:layout_height="Match_parent"/> </linearlayout></inch. Srain. Cube. views. PTR. Ptrframelayout>
Define in code
//default settingsmPtrFrame.setResistance(1.7f);mPtrFrame.setRatioOfHeaderHeightToRefresh(1.2f);mPtrFrame.setDurationToClose(200);mPtrFrame.setDurationToCloseHeader(1000);//defaultisfalsemPtrFrame.setPullToRefresh(false);//defaultistruemPtrFrame.setKeepHeaderWhenRefresh(true);
(3) Initialize Storehouseheader
There are two ways of initializing Storehouseheader:
- Class with a string.
- class using a string array.
Class with a string.
// headerfinalnew StoreHouseHeader(getContext());header.setPadding(0, LocalDisplay.dp2px(1500);/** * using a string, support: A-Z 0-9 - . * you can add more letters by {@link in.srain.cube.views.ptr.header.StoreHousePath#addChar} */header.initWithString(‘Alibaba‘);
class using a string array.
header.initWithStringArray(R.array.storehouse);
R.array.storehouse is an XML file, as follows:
<resources> <string-array name="Storehouse"> <item>0,35,12,42,</Item> <item>12,42,24,35,</Item> <item>24,35,12,28,</Item> <item>0,35,12,28,</Item> <item>0,21,12,28,</Item> <item>12,28,24,21,</Item> <item>24,35,24,21,</Item> <item>24,21,12,14,</Item> <item>0,21,12,14,</Item> <item>0,21,0,7,</Item> <item>12,14,0,7,</Item> <item>12,14,24,7,</Item> <item>24,7,12,0,</Item> <item>0,7,12,0,</Item> </string-array></Resources>
(4) Processing refresh
We can process the refresh by registering Ptrhandler, Ptrhandler is an interface as follows:
Public interface ptrhandler { /** * Check can do refresh or not. For example the content was empty or the first child was in view. * <p/> * {@link In.srain.cube.views.ptr.ptrdefaulthandler#checkcontentcanbepulleddown} */ Public Boolean Checkcandorefresh(FinalPtrframelayout Frame,FinalView content,FinalView header);/** * When refresh begin * * @param Frame */ Public void Onrefreshbegin(FinalPtrframelayout frame);}
Register the Ptrhandler as follows:
Ptrframe.setptrhandler (NewPtrhandler () {@Override Public void Onrefreshbegin(Ptrframelayout frame) {frame.postdelayed (NewRunnable () {@Override Public void Run() {ptrframe.refreshcomplete (); } },1800); }@Override Public Boolean Checkcandorefresh(Ptrframelayout frame, view content, view header) {returnPtrdefaulthandler.checkcontentcanbepulleddown (frame, content, header); }});
In addition, we can show more UI effects by implementing and registering Ptruihandler with Ptrframelayout, as shown here:
Public interface ptruihandler { /** * When the content view had reached top and refresh has been completed, view would be reset. * * @param Frame * * Public void Onuireset(Ptrframelayout frame);/** * Prepare for loading * * @param Frame */ Public void Onuirefreshprepare(Ptrframelayout frame);/** * Perform refreshing UI */ Public void Onuirefreshbegin(Ptrframelayout frame);/** * Perform UI after refresh */ Public void Onuirefreshcomplete(Ptrframelayout frame); Public void Onuipositionchange(Ptrframelayout frame,BooleanIsundertouch,byteStatusintOldposition,intCurrentPosition,floatOldpercent,floatcurrentpercent);}
Little Tricks
Used in conjunction with the Viewpager
disableWhenHorizontalMove();
Used in conjunction with the longpressed
setInterceptEventWhileWorking();
The opening article on the general introduction of so many, follow-up article will continue to do Android-ultra-pull-to-refresh framework analysis and source code analysis.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"User interface: Android-ultra-pull-to-refresh" one: Android-ultra-pull-to-refresh begins