vlayout icon indicating copy to clipboard operation
vlayout copied to clipboard

StaggeredGrid addAdapter后错位

Open wtttc opened this issue 7 years ago • 1 comments

2018-06-15_16_14_42.mp4.zip

zip是复现视频

com.alibaba.android:vlayout:1.2.11之后,StaggeredGrid 数据变化后,视图会错位

1.2.10版本正常

在当前demo也能复现,diff修改如下


diff --git a/examples/src/main/java/com/alibaba/android/vlayout/example/VLayoutActivity.java b/examples/src/main/java/com/alibaba/android/vlayout/example/VLayoutActivity.java
index d17b552..1c3f796 100644
--- a/examples/src/main/java/com/alibaba/android/vlayout/example/VLayoutActivity.java
+++ b/examples/src/main/java/com/alibaba/android/vlayout/example/VLayoutActivity.java
@@ -105,6 +105,8 @@ public class VLayoutActivity extends Activity {
 
     private Runnable trigger;
 
+    DelegateAdapter delegateAdapter;
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -139,7 +141,11 @@ public class VLayoutActivity extends Activity {
         recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
             @Override
             public void onScrollStateChanged(RecyclerView recyclerView, int scrollState) {
-
+                int totalItemCount = layoutManager.getItemCount();
+                int lastVisibleItemPosition = layoutManager.findLastCompletelyVisibleItemPosition();
+                if (totalItemCount <= (lastVisibleItemPosition + 10)) {
+                    onLoadMore();
+                }
             }
 
             @Override
@@ -173,7 +179,7 @@ public class VLayoutActivity extends Activity {
 
         viewPool.setMaxRecycledViews(0, 20);
 
-        final DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager, true);
+        delegateAdapter = new DelegateAdapter(layoutManager, true);
 
         recyclerView.setAdapter(delegateAdapter);
 
@@ -886,4 +892,24 @@ public class VLayoutActivity extends Activity {
             super.finalize();
         }
     }
+
+    public void onLoadMore() {
+        final StaggeredGridLayoutHelper helper = new StaggeredGridLayoutHelper(2, 10);
+        helper.setMargin(20, 10, 10, 10);
+        helper.setPadding(10, 10, 20, 10);
+        helper.setBgColor(0xFF86345A);
+        delegateAdapter.addAdapter(new SubAdapter(VLayoutActivity.this, helper, 3) {
+            @Override
+            public void onBindViewHolder(MainViewHolder holder, int position) {
+                super.onBindViewHolder(holder, position);
+                LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 200);
+                if (position % 2 == 0) {
+                    layoutParams.mAspectRatio = 1.0f;
+                } else {
+                    layoutParams.height = 340 + position % 7 * 20;
+                }
+                holder.itemView.setLayoutParams(layoutParams);
+            }
+        });
+    }
 }


wtttc avatar Jun 15 '18 08:06 wtttc

@wtttc 老哥我想请问下你咋解决视图错位的,我们也碰到了现在很难受~

15189611 avatar Mar 31 '21 03:03 15189611