swipRefreshLayout嵌套listview的冲突解决

在使用5.0的design包下的下拉刷新的时候,当嵌套listview的产生冲突;

导致问题,listView的向上滑动,不受影响,但是向下滑动的时候出现问题,会直接触发下拉刷新!

xml布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#f3f4f8"
    android:orientation="vertical">

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/srl_refresh"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <!--TITLE-->
            <LinearLayout
                android:id="@+id/ll"
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:background="#0066ff"
                android:gravity="center_vertical"
                android:orientation="horizontal">
                <!--广播-->
                <ImageView
                    android:id="@+id/boss_alma_iv1"
                    android:layout_width="23dp"
                    android:layout_height="23dp"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="60dp"
                    android:background="@mipmap/message"/>

                <LinearLayout
                    android:id="@+id/boss_alma_ll"
                    android:layout_width="182dp"
                    android:layout_height="35dp"
                    android:background="@mipmap/boss_alma_one"
                    android:orientation="horizontal">

                    <TextView
                        android:id="@+id/tv_title"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginLeft="60dp"
                        android:text="需求推荐"
                        android:textColor="#203048"
                        android:textSize="16sp"/>

                    <ImageView
                        android:layout_width="6dp"
                        android:layout_height="6dp"
                        android:layout_gravity="center"
                        android:layout_marginLeft="30dp"
                        android:src="@mipmap/boss_alma_right2"/>
                </LinearLayout>
            </LinearLayout>
            <!--公司展示-->
            <ListView
                android:id="@+id/boss_alma_lv"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/ll"
                android:cacheColorHint="@android:color/white"
                android:divider="@null"
                android:fadingEdge="none"
                android:scrollbars="none"/>
        </LinearLayout>
    </android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>


下面的代码是对下拉刷新设置监听,这里就直接将代码考过来微笑

//下拉刷新设置监听
mSrl_refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
    @Override
    public void onRefresh() {
        NeedFragmentBean.getInstance().getShowData();       //获取listview刷新
        NeedFragmentBean.getInstance().getAlmaTitle();      //标题
        //耗时处理,做一个异步的操作
        new Thread(new Runnable() {
            @Override
            public void run() {
                SystemClock.sleep(3000);
                getActivity().runOnUiThread(new Runnable() {     //主线程更新UI
                    @Override
                    public void run() {
                        mSrl_refresh.setRefreshing(false);
                    }
                });
            }
        }).start();
    }
});



//上面的都是基本的处理,下面的是对问题的解决--

//解决下拉刷新和listview的问题
mBoss_alma_lv.setOnScrollListener(new AbsListView.OnScrollListener() {
    @Override
    public void onScrollStateChanged(AbsListView absListView, int i) {

    }

    @Override
    public void onScroll(AbsListView absListView, int firstVisibleItem, int i1, int i2) {
          if (firstVisibleItem == 0){
              mSrl_refresh.setEnabled(true);
          } else{
              mSrl_refresh.setEnabled(false);
          }
    }
});


思路总结:

在listview向下各种滚动的过程中,可以加上一个OnScrollListener,监听listview是否滑到了最顶端的一个item,如果在最顶端,就将swiperefreshlayout设置成setEnabled(true),如果不再最顶端,就设置成setEnabled(false),这样直接就OK,其它的也可以进行效仿奋斗

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值