詹子聪 5 лет назад
Родитель
Сommit
1e27b0826e

+ 2 - 10
app/src/main/java/com/itant/shibei/ui/home/goods/GoodsFragment.java

@@ -3,8 +3,6 @@ package com.itant.shibei.ui.home.goods;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.os.Bundle;
-import android.view.View;
-import android.widget.ImageView;
 
 import androidx.annotation.Nullable;
 import androidx.appcompat.app.AlertDialog;
@@ -54,7 +52,6 @@ public class GoodsFragment extends BaseMVPFragment implements IGoodsView, ITopAc
     /**是否下拉获取数据*/
     private boolean mIsRefresh = true;
 
-    private ImageView iv_empty;
 
     @Override
     public int getLayoutResId() {
@@ -65,7 +62,6 @@ public class GoodsFragment extends BaseMVPFragment implements IGoodsView, ITopAc
     public void onCreateViewFinished(@Nullable Bundle savedInstanceState) {
         super.onCreateViewFinished(savedInstanceState);
 
-        iv_empty = rootView.findViewById(R.id.iv_empty);
         rv_goods = rootView.findViewById(R.id.rv_goods);
         // 必须要设置LayoutManager,否则RecyclerView不知道要使用什么布局,从而在界面上不显示
         LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
@@ -79,6 +75,8 @@ public class GoodsFragment extends BaseMVPFragment implements IGoodsView, ITopAc
         mAdapter = new GoodsAdapter(getActivity(), mGoodsList);
         mAdapter.setGoodsLongClickListener(this::showAdminDialog);
         rv_goods.setAdapter(mAdapter);
+        // 必须先绑定RecyclerView
+        mAdapter.setEmptyView(R.layout.view_empty, rv_goods);
         // 不要滑动一段距离
         rv_goods.smoothScrollToPosition(0);
         srl_goods = rootView.findViewById(R.id.srl_goods);
@@ -201,12 +199,6 @@ public class GoodsFragment extends BaseMVPFragment implements IGoodsView, ITopAc
         if (goodsList != null && goodsList.size() > 0) {
             mCurrentPage++;
         }
-
-        if (mGoodsList.size() == 0) {
-            iv_empty.setVisibility(View.VISIBLE);
-        } else {
-            iv_empty.setVisibility(View.GONE);
-        }
     }
 
     /**

+ 2 - 1
app/src/main/res/layout/view_empty.xml

@@ -8,8 +8,9 @@
         android:id="@+id/iv_empty"
         android:layout_width="@dimen/size_image_big"
         android:layout_height="@dimen/size_image_big"
+        android:layout_marginTop="@dimen/size_image_normal"
+        android:layout_gravity="center_horizontal"
         android:scaleType="fitXY"
         android:src="@mipmap/logo_gray"
-        android:layout_gravity="center"
         android:tint="@color/gray_text_hint"/>
 </FrameLayout>