Essential for lazy people: multiple pull-down refresh, pull-up to load more, and configure custom header ad space library

Essential for lazy people: multiple pull-down refresh, pull-up to load more, and configure custom header ad space library

Introduction

Developers can use BGARefreshLayout-Android to implement various pull-down refresh effects for various controls, pull up to load more, and configure custom header ad slots.

FAQ - Loading more views cannot be displayed.

1. For the height of BGARefreshLayout's direct child controls, use android:layout_height="0dp" and android:layout_weight="1"

  1. <cn.bingoogolapple.refreshlayout.BGARefreshLayout xmlns:android= "http://schemas.android.com/apk/res/android"  
  2. android:id= "@+id/rl_modulename_refresh"  
  3. android:layout_width= "match_parent"  
  4. android:layout_height= "match_parent" >
  5.  
  6. <! -- BGARefreshLayout's direct child control -->  
  7. <AnyView
  8. android:layout_width= "match_parent"  
  9. android:layout_height= "0dp"  
  10. android:layout_weight= "1" />
  11. </cn.bingoogolapple.refreshlayout.BGARefreshLayout>

2. If you use BGARefreshLayout in Fragment

Please initialize BGARefreshLayout in the onCreateView method, not in the onActivityCreated method.

Currently, four pull-down refresh effects have been implemented:

  • Sina Weibo pull-down refresh style (you can set the text for each status and the background of the entire refresh header)
  • Muke.com pull-down refresh style (you can set the logo and color to your own company's style, and set the background of the entire refresh header)
  • Meituan pull-down refresh style (you can set the pictures and animations to your own company's style, and you can set the background of the entire refresh header)
  • Similar to the sticky pull-down refresh style of QQ friend list (the third-order Bezier curve is not adjusted well, the effect is not very good when pulling down at the beginning, you can set the background of the entire refresh header)

A pull-up to load more effects

  • Sina Weibo pulls up to load more (can set background, status text)

Developers can also inherit the abstract class BGARefreshViewHolder and implement corresponding abstract methods to make various pull-down refresh effects [for example, implement the handleScale(float scale, int moveYDistance) method to implement various pull-down refresh animations according to the scale] and pull up to load more special effects. For details, please refer to the implementation methods of BGAMoocStyleRefreshViewHolder, BGANormalRefreshViewHolder, BGAStickinessRefreshViewHolder, and BGAMeiTuanRefreshViewHolder.

Rendering

Basic Use

1. Add Gradle dependency

Eclipse is not supported. It is recommended that friends who are still using Eclipse start to switch to Android Studio.

latestVersion refers to the latest version number of the corresponding library. Don't ask me why I can't find xxxxxxxlatestVersion!

  1. dependencies {
  2. compile 'com.android.support:recyclerview-v7:latestVersion'  
  3. compile 'com.android.support:appcompat-v7:latestVersion'  
  4. compile 'cn.bingoogolapple:bga-refreshlayout:latestVersion@aar' }

2. Add BGARefreshLayout in the layout file

Note: For the height of the content control, use android:layout_height="0dp" and android:layout_weight="1"

  1. <cn.bingoogolapple.refreshlayout.BGARefreshLayout xmlns:android= "http://schemas.android.com/apk/res/android"  
  2. android:id= "@+id/rl_modulename_refresh"  
  3. android:layout_width= "match_parent"  
  4. android:layout_height= "match_parent" > <! -- Content controls -->  
  5. <AnyView
  6. android:layout_width= "match_parent"  
  7. android:layout_height= "0dp"  
  8. android:layout_weight= "1" />
  9. </cn.bingoogolapple.refreshlayout.BGARefreshLayout>

3. Configure BGARefreshLayout in Activity or Fragment

  1. // Let activity or fragment implement BGARefreshLayoutDelegate interface
  2. public class ModuleNameActivity extends AppCompatActivity implements BGARefreshLayout.BGARefreshLayoutDelegate {
  3. private BGARefreshLayout mRefreshLayout;
  4.  
  5. @Override
  6. protected void onCreate(Bundle savedInstanceState) {
  7. super.onCreate(savedInstanceState);
  8. setContentView(R.layout.activity_moudlename);
  9.  
  10. initRefreshLayout();
  11. }
  12.  
  13. private void initRefreshLayout(BGARefreshLayout refreshLayout) {
  14. mRefreshLayout = (BGARefreshLayout) findViewById(R.id.rl_modulename_refresh);
  15. // Set the proxy for BGARefreshLayout
  16. mRefreshLayout.setDelegate(this);
  17. // Set the pull-down refresh and pull-up load more styles Parameter 1: application context, parameter 2: whether to have the pull-up load more function
  18. BGARefreshViewHolder refreshViewHolder = new XXXImplRefreshViewHolder(this, true ))
  19. // Set the pull-down refresh and pull-up load more styles
  20. mRefreshLayout.setRefreshViewHolder(refreshViewHolder);
  21.  
  22.  
  23. // In order to increase the pull-down refresh header and load more versatility, the following optional configuration options are provided -------------START  
  24. // Set the loading control not to be displayed when more are being loaded
  25. // mRefreshLayout.setIsShowLoadingMoreView( false );
  26. // Set the text when loading more
  27. refreshViewHolder.setLoadingMoreText(loadingMoreText);
  28. // Set the background color resource id of the entire loading more controls
  29. refreshViewHolder.setLoadMoreBackgroundColorRes(loadMoreBackgroundColorRes);
  30. // Set the background drawable resource id of the entire loading more controls
  31. refreshViewHolder.setLoadMoreBackgroundDrawableRes(loadMoreBackgroundDrawableRes);
  32. // Set the background color resource id of the pull-down refresh control
  33. refreshViewHolder.setRefreshViewBackgroundColorRes(refreshViewBackgroundColorRes);
  34. // Set the background drawable resource id of the pull-to-refresh control
  35. refreshViewHolder.setRefreshViewBackgroundDrawableRes(refreshViewBackgroundDrawableRes);
  36. // Set a custom header view (optional) Parameter 1: custom header view (such as ad space), Parameter 2: whether pull-up to load more is available
  37. mRefreshLayout.setCustomHeaderView(mBanner, false );
  38. //Optional configuration -------------END  
  39. }
  40.  
  41. @Override
  42. public void onBGARefreshLayoutBeginRefreshing(BGARefreshLayout refreshLayout) {
  43. // Load *** data here
  44.  
  45. if (mIsNetworkEnabled) {
  46. // If the network is available, load the network data
  47. new AsyncTask<Void, Void, Void>() {
  48.  
  49. @Override
  50. protected Void doInBackground(Void... params) {
  51. try {
  52. Thread.sleep(MainActivity.LOADING_DURATION);
  53. } catch (InterruptedException e) {
  54. e.printStackTrace();
  55. }
  56. return   null ;
  57. }
  58.  
  59. @Override
  60. protected void onPostExecute(Void aVoid) {
  61. //After loading is complete, pull down to refresh at the end of the UI thread
  62. mRefreshLayout.endRefreshing();
  63. mDatas.addAll(0, DataEngine.loadNewData());
  64. mAdapter.setDatas(mDatas);
  65. }
  66. } .execute ();
  67. } else {
  68. // Network is unavailable, end pull-down refresh
  69. Toast.makeText(this, "Network is unavailable" , Toast.LENGTH_SHORT).show();
  70. mRefreshLayout.endRefreshing();
  71. }
  72. }
  73.  
  74. @Override
  75. public boolean onBGARefreshLayoutBeginLoadingMore(BGARefreshLayout refreshLayout) {
  76. // Load more data here, or implement pull-up refresh according to product requirements
  77.  
  78. if (mIsNetworkEnabled) {
  79. // If the network is available, load the network data asynchronously and return true to indicate that more data is being loaded
  80. new AsyncTask<Void, Void, Void>() {
  81.  
  82. @Override
  83. protected Void doInBackground(Void... params) {
  84. try {
  85. Thread.sleep(MainActivity.LOADING_DURATION);
  86. } catch (InterruptedException e) {
  87. e.printStackTrace();
  88. }
  89. return   null ;
  90. }
  91.  
  92. @Override
  93. protected void onPostExecute(Void aVoid) {
  94. //After loading is complete, end the UI thread to load more
  95. mRefreshLayout.endLoadingMore();
  96. mAdapter.addDatas(DataEngine.loadMoreData());
  97. }
  98. } .execute ();
  99.  
  100. return   true ;
  101. } else {
  102. // If the network is unavailable, return false and do not display that more content is loading.
  103. Toast.makeText(this, "Network is unavailable" , Toast.LENGTH_SHORT).show();
  104. return   false ;
  105. }
  106. }
  107.  
  108. // Control entering the refreshing state through code. Application scenario: Some applications are called in the onStart method of activity and automatically enter the refreshing state to obtain *** data
  109. public void beginRefreshing() {
  110. mRefreshLayout.beginRefreshing();
  111. }
  112.  
  113. //Control entering the loading more state through code
  114. public void beginLoadingMore() {
  115. mRefreshLayout.beginLoadingMore();
  116. }
  117.  
  118. }

<<:  How to manually backup your SMS/MMS on Android?

>>:  A new method to improve the survival rate of Android application processes (Part 1)

Recommend

Three ways to identify channel fraud from operational data!

Recently, when I was chatting with a CP friend, h...

How to do fan marketing? Five methodologies for fan marketing!

% ignore_pre_1 % Luo Yonghao is the first generati...

Xiaohongshu promotion method: How to promote effectively?

When you have a fan "offline", and he s...

How to solve the problem of too many users connected to the Win server terminal?

The test succeeded under 2003 and failed under 20...

Friends who are planning to buy an eye protection lamp, don’t panic!

Nowadays, people are paying more and more attenti...

Solid info! Tips for promoting the Mayu APP!

How to carry out advertising promotion on Mayu AP...

Bloomberg: Global smartphone market will go from bad to worse

On the evening of May 11, Bloomberg published an ...

Bilibili (Bilibili) Product Analysis

Bilibili was originally a two-dimensional website...