GithubHelp home page GithubHelp logo

Comments (10)

binglingziyu avatar binglingziyu commented on August 28, 2024 3

@tsunamilx 我也遇到这问题,临时找到个解决办法,你可以试试
@Aspsine 作者有没有计划解决这个问题 🙏🙏🙏🙏🙏

public class MainHomeFragment extends BaseFragment implements AppBarLayout.OnOffsetChangedListener{

    @Bind(R.id.app_bar_layout)
    AppBarLayout app_bar_layout;
    @Bind(R.id.swipeToLoadView)
    SwipeToLoadView swipeToLoadView;

    private void initDisplay() {
        app_bar_layout.addOnOffsetChangedListener(this);
    }

    @Override
    public void onOffsetChanged(AppBarLayout appBarLayout, int i) {
        // i == 0 就代表AppBarLayout展开了
        if (!swipeToLoadView.isRefreshing()) 
            swipeToLoadView.setRefreshEnabled(i==0);
    }
}

from swipetoloadlayout.

act262 avatar act262 commented on August 28, 2024 2

让子Fragment实现接口SwipeChildListener

public interface SwipeChildListener {

    /**
     * 启用下拉刷新功能
     *
     * @see SwipeLayout#enableRefresh()
     */
    void enableRefresh();

    /**
     * 禁用下拉刷新功能
     *
     * @see SwipeLayout#disableRefresh()
     */
    void disableRefresh();
}

然后在添加AppBarLayout滚动的监听事件

 // 监听头部滚动状态
 mAppBarLayout.addOnOffsetChangedListener(this);
 @Override
 public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
        float alpha = (appBarLayout.getTotalScrollRange() + verticalOffset) * 1.0f / appBarLayout.getTotalScrollRange();

        // 全面展开状态,在一定范围内
        boolean fullExpanded = verticalOffset > -10;

        Fragment fragment = mAdapter.mFragmentList.get(mPager.getCurrentItem());
        if (fragment != null && fragment instanceof SwipeChildListener) {
            SwipeChildListener listener = (SwipeChildListener) fragment;
            // 只有在全面展开状态时才允许子页面开启刷新功能以防止手势冲突
            if (fullExpanded) {
                listener.enableRefresh();
            } else {
                listener.disableRefresh();
            }
        }
 }

子Fragment实现接口方法:

 @Override
    public void enableRefresh() {
        mSwipeLayout.setRefreshEnabled(true);;
    }

    @Override
    public void disableRefresh() {
        mSwipeLayout.setRefreshEnabled(false);
    }

from swipetoloadlayout.

Aspsine avatar Aspsine commented on August 28, 2024

意思是,当AppbarLayout处于缩起状态时,下拉先让其展开,完全展开后再触发刷新吧?

from swipetoloadlayout.

tsunamilx avatar tsunamilx commented on August 28, 2024

对是的

from swipetoloadlayout.

tsunamilx avatar tsunamilx commented on August 28, 2024

录屏在此
record

from swipetoloadlayout.

tsunamilx avatar tsunamilx commented on August 28, 2024

请问有什么进展吗

from swipetoloadlayout.

Aspsine avatar Aspsine commented on August 28, 2024

@tsunamilx 抱歉,最近比较忙,你可以先尝试自己修复一下。

from swipetoloadlayout.

tsunamilx avatar tsunamilx commented on August 28, 2024

还是你们厉害,我是直接修改了SwipeToLoadLayout,把Toolbar塞进了SwipeToLoadLayout里面,然后在onCheckCanRefresh()方法里判断了Toolbar的可见高度来判定是否开始刷新。

from swipetoloadlayout.

robinxdroid avatar robinxdroid commented on August 28, 2024

@act262 还需要再接口中补充一个isRefreshing的方法,否则在刷新状态时,往上轻轻一推,refresh header会收不回去

public interface SwipeChildListener {

    boolean isRefreshing();

    void enableRefresh();

    void disableRefresh();
}

mAppBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                float alpha = (appBarLayout.getTotalScrollRange() + verticalOffset) * 1.0f / appBarLayout.getTotalScrollRange();
                if(!swipeChildListener.isRefreshing()){
                    // 全面展开状态,在一定范围内
                    boolean fullExpanded = verticalOffset > -10;

                    // 只有在全面展开状态时才允许子页面开启刷新功能以防止手势冲突
                    if (fullExpanded) {
                        swipeChildListener.enableRefresh();
                    } else {
                        swipeChildListener.disableRefresh();
                    }
                }
            }
        });

from swipetoloadlayout.

act262 avatar act262 commented on August 28, 2024

是的,还有加载footer的2个方法也需要放到接口处理一下,可以处理子页面内容在没有充满父布局导致的问题

from swipetoloadlayout.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.