From 50e3ad4bf1d57aa95080f4a90026bd874198cd66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=80=80=E5=BA=B7?= <229144497@qq.com> Date: Fri, 13 Aug 2021 09:17:34 +0800 Subject: [PATCH] =?UTF-8?q?[Bug4030]=E3=80=90RecyclerView-FastScroll?= =?UTF-8?q?=E3=80=91=E3=80=90=E7=AC=AC=E4=BA=8C=E8=BD=AE=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E3=80=91=E8=BF=9E=E7=BB=AD=E5=A4=9A=E6=AC=A1=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E6=BB=91=E5=8A=A8=E5=92=8C=E7=BF=BB=E9=A1=B5=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E5=90=8E=EF=BC=8C=E5=BA=95=E9=83=A8=E5=88=87=E6=8D=A2=E5=88=B0?= =?UTF-8?q?Page2=E4=BD=86=E9=A1=B5=E9=9D=A2=E5=86=85=E5=AE=B9=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E7=9A=84=E8=BF=98=E6=98=AFPage1=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sample/slice/MainAbilitySlice.java | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/entry/src/main/java/com/simplecityapps/recyclerview_fastscroll/sample/slice/MainAbilitySlice.java b/entry/src/main/java/com/simplecityapps/recyclerview_fastscroll/sample/slice/MainAbilitySlice.java index 6c7f678..ea5b8ad 100644 --- a/entry/src/main/java/com/simplecityapps/recyclerview_fastscroll/sample/slice/MainAbilitySlice.java +++ b/entry/src/main/java/com/simplecityapps/recyclerview_fastscroll/sample/slice/MainAbilitySlice.java @@ -26,6 +26,7 @@ public class MainAbilitySlice extends AbilitySlice { private float lastV; Point pt = new Point(); + @Override public void onStart(Intent intent) { super.onStart(intent); @@ -40,6 +41,7 @@ public class MainAbilitySlice extends AbilitySlice { Optional display = DisplayManager.getInstance().getDefaultDisplay(MainAbilitySlice.this); display.get().getSize(pt); + text1.setBindStateChangedListener(new Component.BindStateChangedListener() { @Override public void onComponentBoundToWindow(Component component) { @@ -52,6 +54,7 @@ public class MainAbilitySlice extends AbilitySlice { } }); + text2.setBindStateChangedListener(new Component.BindStateChangedListener() { @Override public void onComponentBoundToWindow(Component component) { @@ -65,51 +68,53 @@ public class MainAbilitySlice extends AbilitySlice { } }); pageslider.setProvider(new PagerAdapter(this)); - pageslider.addPageChangedListener(new PageSlider.PageChangedListener() { @Override public void onPageSliding(int i, float v, int i1) { - if(i1 < lastV&& lastV==1){ + if (v == 0 && i1 == 0) { + adjust(); + return; + } + if (i1 < lastV && lastV == 1) { lastV = 1; - }else{ + } else { lastV = i1; } System.out.println("addPageChangedListener onPageSliding " + i + "==" + lastV + "==" + i1); if (lastV > 0) { - if(v>0.5){ + if (v > 0.5) { text1.setTextColor(new Color(Color.getIntColor("#787878"))); text2.setTextColor(new Color(Color.getIntColor("#000000"))); text1.setTranslationX(0); - text2.setTranslationX(textLeft2-textLeft2*(v-0.5f)); - }else{ - text1.setTranslationX(textLeft1-textLeft1*v*2); + text2.setTranslationX(textLeft2 - textLeft2 * (v - 0.5f)); + } else { + text1.setTranslationX(textLeft1 - textLeft1 * v * 2); text2.setTranslationX(textLeft2); text1.setTextColor(new Color(Color.getIntColor("#000000"))); text2.setTextColor(new Color(Color.getIntColor("#787878"))); } } else { - if(v>0.5){ + if (v > 0.5) { text2.setTranslationX(textLeft2); - text1.setTranslationX(textLeft1*(v-0.5f)*2); + text1.setTranslationX(textLeft1 * (v - 0.5f) * 2); text1.setTextColor(new Color(Color.getIntColor("#000000"))); text2.setTextColor(new Color(Color.getIntColor("#787878"))); - }else{ - text2.setTranslationX(textLeft1+textLeft1*v*2); + } else { + text2.setTranslationX(textLeft1 + textLeft1 * v * 2); text1.setTranslationX(0); text1.setTextColor(new Color(Color.getIntColor("#787878"))); text2.setTextColor(new Color(Color.getIntColor("#000000"))); } } - - } @Override public void onPageSlideStateChanged(int i) { System.out.println("addPageChangedListener onPageSlideStateChanged " + i); + adjust(); } @Override @@ -128,4 +133,15 @@ public class MainAbilitySlice extends AbilitySlice { public void onForeground(Intent intent) { super.onForeground(intent); } + + + private void adjust() { + if (pageslider.getCurrentPage() == 0) { + text1.setTranslationX(textLeft1); + text2.setTranslationX(textLeft2); + } else { + text2.setTranslationX(textLeft1); + text1.setTranslationX(0); + } + } } -- Gitee