scwang90 / SmartRefreshLayout

🔥下拉刷新、上拉加载、二级刷新、淘宝二楼、RefreshLayout、OverScroll,Android智能下拉刷新框架,支持越界回弹、越界拖动,具有极强的扩展性,集成了几十种炫酷的Header和 Footer。
https://segmentfault.com/a/1190000010066071
Apache License 2.0
24.88k stars 4.94k forks source link

莫名卡顿。。。 #134

Closed parcool closed 7 years ago

parcool commented 7 years ago

自动刷新,成功后。上滑列表,一次性请求100条测试数据,卡顿。。。我的adapter已注释所有可能消耗UI的代码还是一样。但是滑过去后再次随便滑动都非常流畅。已setEnableLoadmore(false)。

parcool commented 7 years ago

我知道这样说没法定位问题。稍后贴完整代码。

parcool commented 7 years ago

activity_all_orders3.xml


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

    <com.scwang.smartrefresh.layout.SmartRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/srl"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/xrv_overview"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </com.scwang.smartrefresh.layout.SmartRefreshLayout>

</RelativeLayout>

OrdersAllTestActivity.java

public class OrdersAllTestActivity extends BaseActivityWithTitle {

    private SmartRefreshLayout srl;
    private RecyclerView recyclerView;
    private OrdersDoneAdapterTest ordersAllAdapter;
    private List<OrderModel> mListOrderModel = new ArrayList<>();

    @Override
    protected String setTitle() {
        return getString(R.string.all_orders);
    }

    @Override
    protected boolean isBackShow() {
        return true;
    }

    @Override
    protected boolean isMenuVisible() {
        return true;
    }

    @Override
    protected void initViews(@Nullable Bundle savedInstanceState) {
        srl = (SmartRefreshLayout) findViewById(R.id.srl);
        srl.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
//                ordersAllAdapter.setEnableLoadMore(false);
                getOrders(true);
            }
        });
        srl.setEnableLoadmore(false);
        recyclerView = (RecyclerView) findViewById(R.id.xrv_overview);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        ordersAllAdapter = new OrdersDoneAdapterTest(mListOrderModel);
        recyclerView.setAdapter(ordersAllAdapter);

    }

    @Override
    protected void setOnClickListeners() {

    }

    @Override
    protected void initData(@Nullable Bundle savedInstanceState) {

    }

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_all_orders3;
    }

    @Override
    protected void reload() {

    }

    @Override
    protected boolean isLoadViewEnable() {
        return false;
    }

    private int page = 1;

    private void getOrders(boolean isRefresh) {
        Map<Object, Object> map = new HashMap<>();
        map.put("orderType", OrderType.ALL);
        if (paoPaoApplication == null || paoPaoApplication.getUserModel() == null || paoPaoApplication.getUserModel().getTk() == null) {
            return;
        }
        map.put("tk", paoPaoApplication.getUserModel().getTk());
        if (isRefresh) {
            page = 1;
        }
        map.put("page", page);
        map.put("rows", AppConfig.PAGE_COUNT);

        APIService.getInstance().getOrderList(map, new DoOnSubscriber<List<OrderModel>>() {
            @Override
            public void doOnSubscriber() {

            }

            @Override
            public void onCompleted() {
            }

            @Override
            public void onNext(List<OrderModel> orderModels) {
                srl.finishRefresh(0, true);
                mListOrderModel.addAll(orderModels);
                ordersAllAdapter.notifyItemRangeInserted(mListOrderModel.size() - orderModels.size(), orderModels.size());
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
            }
        });

    }
}

adapter_orders_done.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorWhite"
    android:orientation="vertical">

    <View
        android:layout_width="match_parent"
        android:layout_height="1px"
        android:background="@color/nav_line" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/activity_half_horizontal_margin"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:layout_marginTop="@dimen/activity_half_horizontal_margin"
        android:gravity="center_vertical"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/tv_number"
            android:layout_width="26dp"
            android:layout_height="26dp"
            android:background="@color/colorPrimary"
            android:gravity="center"
            android:text="1"
            android:textColor="@color/colorWhite" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:text="@string/total_time_cast"
            android:textColor="@color/textColorPrimary"
            android:textSize="16sp" />

        <TextView
            android:id="@+id/tv_time_past"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:text="03:23"
            android:textColor="@color/red"
            android:textSize="16sp" />

        <View
            android:visibility="gone"
            android:layout_width="0dp"
            android:layout_height="1dp"
            android:layout_weight="1" />

        <LinearLayout
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <LinearLayout
                android:gravity="right"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/total_pay"
                    android:textColor="@color/textColorThird"
                    android:textSize="14sp" />

                <TextView
                    android:id="@+id/tv_pay_money"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="4dp"
                    android:text="¥6.00"
                    android:textColor="@color/textColorPrimary"
                    android:textSize="16sp" />
            </LinearLayout>

            <TextView
                android:layout_gravity="right"
                android:textColor="@color/textColorThird"
                android:id="@+id/tv_money_detail"
                android:textSize="12sp"
                android:text="预支付 ¥6.00 + 加价 ¥4.00"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>

    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1px"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:background="@color/nav_line" />
    <!--取-->
    <LinearLayout
        android:id="@+id/ll_from"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="8dp"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:paddingTop="8dp"
        android:gravity="center_vertical"
        android:orientation="horizontal">

        <View
            android:layout_width="10dp"
            android:layout_height="10dp"
            android:background="@drawable/circle_solid_grey_10dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/activity_half_horizontal_margin"
            android:layout_marginRight="@dimen/activity_half_horizontal_margin"
            android:text="@string/from"
            android:textColor="@color/textColorSecond" />

        <TextView
            android:id="@+id/tv_from"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="中枢城区竹梅箱58号"
            android:textColor="@color/textColorPrimary" />

        <ImageView
            android:layout_width="18dp"
            android:layout_height="18dp"
            android:src="@mipmap/ic_location" />
    </LinearLayout>
    <!--送-->
    <LinearLayout
        android:id="@+id/ll_to"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="8dp"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:paddingBottom="8dp"
        android:gravity="center_vertical"
        android:orientation="horizontal">

        <View
            android:layout_width="10dp"
            android:layout_height="10dp"
            android:background="@drawable/circle_solid_grey_10dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/activity_half_horizontal_margin"
            android:layout_marginRight="@dimen/activity_half_horizontal_margin"
            android:text="@string/to"
            android:textColor="@color/textColorSecond" />

        <TextView
            android:id="@+id/tv_to"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="国酒新城一期"
            android:textColor="@color/textColorPrimary" />

        <ImageView
            android:layout_width="18dp"
            android:layout_height="18dp"
            android:src="@mipmap/ic_location" />
    </LinearLayout>
    <!--用户信息-->
    <LinearLayout
        android:id="@+id/ll_tel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:gravity="center_vertical"
        android:orientation="horizontal">

        <com.facebook.drawee.view.SimpleDraweeView
            android:visibility="gone"
            android:id="@+id/sdv_user"
            android:layout_width="32dp"
            android:layout_height="32dp"
            app:roundAsCircle="true"
            app:roundBottomLeft="false"
            app:roundBottomRight="false"
            app:roundingBorderWidth="1.0dip" />

        <TextView
            android:id="@+id/tv_user_nickname"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/activity_half_horizontal_margin"
            android:layout_weight="1"
            android:text="张先生"
            android:textColor="@color/textColorSecond" />

        <ImageView
            android:layout_width="18dp"
            android:layout_height="18dp"
            android:src="@mipmap/ic_tel" />
    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1px"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:background="@color/nav_line" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:orientation="horizontal"
        android:paddingBottom="@dimen/activity_half_horizontal_margin"
        android:paddingTop="@dimen/activity_half_horizontal_margin">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/order_number"
            android:textColor="@color/textColorThird"
            android:textSize="14sp" />

        <TextView
            android:id="@+id/tv_order_number"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="4dp"
            android:layout_weight="1"
            android:text="123456790123456789"
            android:textColor="@color/textColorSecond"
            android:textSize="14sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/done_time"
            android:textColor="@color/textColorThird"
            android:textSize="14sp" />

        <TextView
            android:id="@+id/tv_order_time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="4dp"
            android:text="16:56:21"
            android:textColor="@color/textColorSecond"
            android:textSize="14sp" />
    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1px"
        android:background="@color/nav_line" />
</LinearLayout>

OrdersDoneAdapterTest.java

public class OrdersDoneAdapterTest extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<OrderModel> mList;

    public OrdersDoneAdapterTest(List<OrderModel> mList) {
        this.mList = mList;
    }
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_orders_done, parent, false);
        final MyViewHolder myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder1, int position) {
        if (holder1 instanceof MyViewHolder) {
            MyViewHolder holder = (MyViewHolder) holder1;
            holder.tvFrom.setText(mList.get(position).getStartAddr());
            holder.tvTo.setText(mList.get(position).getEndAddr());
            holder.tvUserNickname.setText(mList.get(position).getUserName());
            holder.llTel.setTag(mList.get(position).getUserPhone());
            holder.tvOrderNumber.setText(mList.get(position).getOrderNo());
        }
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        TextView tvNumber, tvTimePast, tvPayMoney, tvFrom, tvTo, tvUserNickname, tvSeconds, tvOrderNumber, tvOrderTime, tvWords, tvMoneyDetail;
        LinearLayout llFrom, llTo, llTel;

        MyViewHolder(View itemView) {
            super(itemView);
            tvNumber = (TextView) itemView.findViewById(R.id.tv_number);
            tvTimePast = (TextView) itemView.findViewById(R.id.tv_time_past);
            tvPayMoney = (TextView) itemView.findViewById(R.id.tv_pay_money);
            tvFrom = (TextView) itemView.findViewById(R.id.tv_from);
            tvTo = (TextView) itemView.findViewById(R.id.tv_to);
            tvUserNickname = (TextView) itemView.findViewById(R.id.tv_user_nickname);
            tvSeconds = (TextView) itemView.findViewById(R.id.tv_seconds);
            tvOrderNumber = (TextView) itemView.findViewById(R.id.tv_order_number);
            tvOrderTime = (TextView) itemView.findViewById(R.id.tv_order_time);
            llFrom = (LinearLayout) itemView.findViewById(R.id.ll_from);
            llTo = (LinearLayout) itemView.findViewById(R.id.ll_to);
            llTel = (LinearLayout) itemView.findViewById(R.id.ll_tel);
            tvMoneyDetail = (TextView) itemView.findViewById(R.id.tv_money_detail);
        }
    }

}
parcool commented 7 years ago

不是刷新框架的锅。估计是view层的问题。不好意思没搞清楚就开了个新issue

HalyangDream commented 7 months ago

我也是这样设置setEnableLoadmore(false)就不卡顿,发现原因了吗