All Projects → bingoogolapple → Bgarefreshlayout Android

bingoogolapple / Bgarefreshlayout Android

多种下拉刷新效果、上拉加载更多、可配置自定义头部广告位

Programming Languages

java
68154 projects - #9 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to Bgarefreshlayout Android

Liquidrefreshlayout
Liquid Refresh Layout is a simple SwipeToRefresh library that helps you easily integrate SwipeToRefresh and performs simple clean liquid animation
Stars: ✭ 114 (-97.32%)
Mutual labels:  refreshlayout
React Native Smartrefreshlayout
基于android SmartRefreshLayout https://github.com/scwang90/SmartRefreshLayout 开发的插件,可提供类似ios的弹性刷新
Stars: ✭ 240 (-94.37%)
Mutual labels:  refreshlayout
ParticlesRefreshLayout-android
Particles Refresh Layout library for Android
Stars: ✭ 15 (-99.65%)
Mutual labels:  refreshlayout
Widgetlayout
自定义ViewGroup的集合(有 kotlin 实现分支):提高编写效率和 UI 绘制性能,少嵌套,易用易扩展。
Stars: ✭ 130 (-96.95%)
Mutual labels:  refreshlayout
Krefreshlayout
强大的下拉刷新库,定制任意Header。比官方SwipRefrehLayout处理更加友好(Kotlin、Java双版本)
Stars: ✭ 217 (-94.91%)
Mutual labels:  refreshlayout
Multi-SwipeToRefreshLayout
多方向支持刷新view通用布局
Stars: ✭ 17 (-99.6%)
Mutual labels:  refreshlayout
Qrefreshlayout
下拉刷新,上拉加载更多,自动加载更多,用法同SwipeRefreshLayout,兼容所有view,兼容nested滚动,可以自定义header footer,支持下拉到二楼
Stars: ✭ 75 (-98.24%)
Mutual labels:  refreshlayout
Net
Android上强大的网络请求
Stars: ✭ 344 (-91.93%)
Mutual labels:  refreshlayout
Shswiperefreshlayout
Android 升级版 SwipeRefreshLayout,支持RecyclerView、ScrollView等大部分组件,下拉刷新(Refresh)和上拉加载(Loadmore),支持自定义HeaderView和FooterView
Stars: ✭ 236 (-94.46%)
Mutual labels:  refreshlayout
Chopin
A Android Refresh Layout including refresh header and load more and sticky header
Stars: ✭ 15 (-99.65%)
Mutual labels:  refreshlayout
React Native Mjrefresh
基于ios MJRefresh https://github.com/CoderMJLee/MJRefresh 开发的插件,可提供自定义的弹性刷新
Stars: ✭ 140 (-96.71%)
Mutual labels:  refreshlayout
Springview
🔥 A custom view pull to refresh,support ScrollView,ListView,RecyclerView,WebView and all another views, easy to use
Stars: ✭ 1,936 (-54.56%)
Mutual labels:  refreshlayout
PowerRefresh
Support nested scroll for refresh and load more.
Stars: ✭ 64 (-98.5%)
Mutual labels:  refreshlayout
Xrefreshlayout
【已过时,不再更新,请使用更强大的SmartRefreshLayout!】A refresh layout(无侵入下拉刷新和加载布局), can refresh RecyclerView for all LayoutManager, NestedScrollView。
Stars: ✭ 127 (-97.02%)
Mutual labels:  refreshlayout
ZRefreshLayout
一个可以全局随意配置头部的下拉刷新与上拉加载库;
Stars: ✭ 30 (-99.3%)
Mutual labels:  refreshlayout
Meibasemodule
A powerful multi-function library that extended base activity for Android!
Stars: ✭ 78 (-98.17%)
Mutual labels:  refreshlayout
goRefresh
让下拉刷新炫酷起来~轻松接入lottie动画,支持listview recyclerview scrollerview webview 。同时支持listview和recyclerview上拉加载
Stars: ✭ 24 (-99.44%)
Mutual labels:  refreshlayout
Brv
Android上最强大的RecyclerView库
Stars: ✭ 345 (-91.9%)
Mutual labels:  refreshlayout
SwipeRefreshPlus
参考swiperefreshlayout添加下拉加载更多
Stars: ✭ 24 (-99.44%)
Mutual labels:  refreshlayout
HorizontalRefreshLayout
a android layout widget for horizontal drag refresh action (viewpager or recyclerview)
Stars: ✭ 75 (-98.24%)
Mutual labels:  refreshlayout

🏃BGARefreshLayout-Android🏃

Android Arsenal License Download

开发者使用 BGARefreshLayout-Android 可以对各种控件实现多种下拉刷新效果、上拉加载更多以及配置自定义头部广告位

测试 BGARefreshLayout 与 Activity、Fragment、ViewPager 的各种嵌套的 Demo

常见问题-加载更多视图无法显示

1.BGARefreshLayout 的直接子控件的高度请使用 android:layout_height="0dp" 和 android:layout_weight="1"

<cn.bingoogolapple.refreshlayout.BGARefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rl_modulename_refresh"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- BGARefreshLayout 的直接子控件 -->
    <AnyView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
</cn.bingoogolapple.refreshlayout.BGARefreshLayout>

2.如果是在 Fragment 中使用 BGARefreshLayout

请在 onCreateView 方法中初始化 BGARefreshLayout,不要在 onActivityCreated 方法中初始化

目前已经实现了四种下拉刷新效果:

  • 新浪微博下拉刷新风格(可设置各种状态是的文本,可设置整个刷新头部的背景)
  • 慕课网下拉刷新风格(可设置其中的 logo 和颜色成自己公司的风格,可设置整个刷新头部的背景)
  • 美团下拉刷新风格(可设置其中的图片和动画成自己公司的风格,可设置整个刷新头部的背景)
  • 类似 qq 好友列表黏性下拉刷新风格(三阶贝塞尔曲线没怎么调好,刚开始下拉时效果不太好,可设置整个刷新头部的背景)

一种上拉加载更多效果

  • 新浪微博上拉加载更多(可设置背景、状态文本)

开发者也可以继承 BGARefreshViewHolder 这个抽象类,实现相应地抽象方法做出格式各样的下拉刷新效果【例如实现 handleScale(float scale, int moveYDistance) 方法,根据 scale 实现各种下拉刷新动画】和上拉加载更多特效,可参考 BGAMoocStyleRefreshViewHolder、BGANormalRefreshViewHolder、BGAStickinessRefreshViewHolder、BGAMeiTuanRefreshViewHolder 的实现方式。

目前存在的问题

  • 当配置自定义头部广告位可滚动时,内容区域和广告位还不能平滑过度。
  • 当 BGAStickyNavLayout 中嵌套 RecyclerView 或 AbsListView,并且第一页的最后一个 item 刚好在最底部时,加载更多视图会悬浮在最后一个 item 上面
  • 正在刷新或加载更多时,用户上下滑动不会让下拉刷新视图和加载更多视图跟着滑动

效果图

bga_refreshlayout1 bga_refreshlayout2 bga_refreshlayout3 bga_refreshlayout4 bga_refreshlayout5 bga_refreshlayout6

基本使用

1.添加 Gradle 依赖

  • maven { url 'https://jitpack.io' } 添加到 root build.gradle 的 repositories 中
  • 在 app build.gradle 中添加如下依赖,末尾的「latestVersion」指的是徽章 里的版本名称,请自行替换
dependencies {
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.github.bingoogolapple:BGARefreshLayout-Android:latestVersion'
}

2.在布局文件中添加 BGARefreshLayout

注意:内容控件的高度请使用 android:layout_height="0dp" 和 android:layout_weight="1"

<cn.bingoogolapple.refreshlayout.BGARefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rl_modulename_refresh"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- 内容控件 -->
    <AnyView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
</cn.bingoogolapple.refreshlayout.BGARefreshLayout>

3.在 Activity 或者 Fragment 中配置 BGARefreshLayout

// 让 activity 或者 fragment 实现 BGARefreshLayoutDelegate 接口
public class ModuleNameActivity extends AppCompatActivity implements BGARefreshLayout.BGARefreshLayoutDelegate {
    private BGARefreshLayout mRefreshLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_moudlename);

        initRefreshLayout();
    }

    private void initRefreshLayout(BGARefreshLayout refreshLayout) {
        mRefreshLayout = (BGARefreshLayout) findViewById(R.id.rl_modulename_refresh);
        // 为BGARefreshLayout 设置代理
        mRefreshLayout.setDelegate(this);
        // 设置下拉刷新和上拉加载更多的风格     参数1:应用程序上下文,参数2:是否具有上拉加载更多功能
        BGARefreshViewHolder refreshViewHolder = new XXXImplRefreshViewHolder(this, true))
        // 设置下拉刷新和上拉加载更多的风格
        mRefreshLayout.setRefreshViewHolder(refreshViewHolder);


        // 为了增加下拉刷新头部和加载更多的通用性,提供了以下可选配置选项  -------------START
        // 设置正在加载更多时不显示加载更多控件
        // mRefreshLayout.setIsShowLoadingMoreView(false);
        // 设置正在加载更多时的文本
        refreshViewHolder.setLoadingMoreText(loadingMoreText);
        // 设置整个加载更多控件的背景颜色资源 id
        refreshViewHolder.setLoadMoreBackgroundColorRes(loadMoreBackgroundColorRes);
        // 设置整个加载更多控件的背景 drawable 资源 id
        refreshViewHolder.setLoadMoreBackgroundDrawableRes(loadMoreBackgroundDrawableRes);
        // 设置下拉刷新控件的背景颜色资源 id
        refreshViewHolder.setRefreshViewBackgroundColorRes(refreshViewBackgroundColorRes);
        // 设置下拉刷新控件的背景 drawable 资源 id
        refreshViewHolder.setRefreshViewBackgroundDrawableRes(refreshViewBackgroundDrawableRes);
        // 设置自定义头部视图(也可以不用设置)     参数1:自定义头部视图(例如广告位), 参数2:上拉加载更多是否可用
        mRefreshLayout.setCustomHeaderView(mBanner, false);
        // 可选配置  -------------END
    }

    @Override
    public void onBGARefreshLayoutBeginRefreshing(BGARefreshLayout refreshLayout) {
        // 在这里加载最新数据

        if (mIsNetworkEnabled) {
            // 如果网络可用,则加载网络数据
            new AsyncTask<Void, Void, Void>() {

                @Override
                protected Void doInBackground(Void... params) {
                    try {
                        Thread.sleep(MainActivity.LOADING_DURATION);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    return null;
                }

                @Override
                protected void onPostExecute(Void aVoid) {
                    // 加载完毕后在 UI 线程结束下拉刷新
                    mRefreshLayout.endRefreshing();
                    mDatas.addAll(0, DataEngine.loadNewData());
                    mAdapter.setDatas(mDatas);
                }
            }.execute();
        } else {
            // 网络不可用,结束下拉刷新
            Toast.makeText(this, "网络不可用", Toast.LENGTH_SHORT).show();
            mRefreshLayout.endRefreshing();
        }
    }

    @Override
    public boolean onBGARefreshLayoutBeginLoadingMore(BGARefreshLayout refreshLayout) {
        // 在这里加载更多数据,或者更具产品需求实现上拉刷新也可以

        if (mIsNetworkEnabled) {
            // 如果网络可用,则异步加载网络数据,并返回 true,显示正在加载更多
            new AsyncTask<Void, Void, Void>() {

                @Override
                protected Void doInBackground(Void... params) {
                    try {
                        Thread.sleep(MainActivity.LOADING_DURATION);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    return null;
                }

                @Override
                protected void onPostExecute(Void aVoid) {
                    // 加载完毕后在 UI 线程结束加载更多
                    mRefreshLayout.endLoadingMore();
                    mAdapter.addDatas(DataEngine.loadMoreData());
                }
            }.execute();

            return true;
        } else {
            // 网络不可用,返回 false,不显示正在加载更多
            Toast.makeText(this, "网络不可用", Toast.LENGTH_SHORT).show();
            return false;
        }
    }

    // 通过代码方式控制进入正在刷新状态。应用场景:某些应用在 activity 的 onStart 方法中调用,自动进入正在刷新状态获取最新数据
    public void beginRefreshing() {
        mRefreshLayout.beginRefreshing();
    }

    // 通过代码方式控制进入加载更多状态
    public void beginLoadingMore() {
        mRefreshLayout.beginLoadingMore();
    }

}

更多详细用法请查看 Wiki 或者 Demo

Demo 中使用到了我的另外三个库,欢迎大家 Star 😄

关于我

个人主页 邮箱 BGA 系列开源库 QQ 群 GitHub 喵(专注于 GitHub 等一切与程序员有关的内容)
bingoogolapple.cn [email protected] BGA_CODE_CLUB GitHub喵

打赏支持

如果觉得 BGA 系列开源库对您有用,请随意打赏。如果猿友有打算购买 Lantern,可以使用我的邀请码「YFQ9Q3B」购买,双方都赠送三个月的专业版使用时间。

License

Copyright 2015 bingoogolapple

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].