From 8c6ff087fcce97a37f8a1db7ea36e03439b5af8d Mon Sep 17 00:00:00 2001 From: gxj0116 Date: Fri, 18 Feb 2022 10:55:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DrecyclerView.getViewTreeObser?= =?UTF-8?q?ver().removeOnGlobalLayoutListener(this)=E5=9C=A8Android4.2?= =?UTF-8?q?=E4=BB=A5=E4=B8=8B=E8=AE=BE=E5=A4=87=E5=B4=A9=E6=BA=83=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复recyclerView.getViewTreeObserver().removeOnGlobalLayoutListener(this)在Android4.2以下设备崩溃的问题 --- .../com/jiang/android/indicatordialog/IndicatorDialog.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/indicator/src/main/java/com/jiang/android/indicatordialog/IndicatorDialog.java b/indicator/src/main/java/com/jiang/android/indicatordialog/IndicatorDialog.java index 586c8a3..ee064b0 100644 --- a/indicator/src/main/java/com/jiang/android/indicatordialog/IndicatorDialog.java +++ b/indicator/src/main/java/com/jiang/android/indicatordialog/IndicatorDialog.java @@ -124,7 +124,11 @@ private void addRecyclerView2Layout() { @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) @Override public void onGlobalLayout() { - recyclerView.getViewTreeObserver().removeOnGlobalLayoutListener(this); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + recyclerView.getViewTreeObserver().removeOnGlobalLayoutListener(this); + } else { + recyclerView.getViewTreeObserver().removeGlobalOnLayoutListener(this); + } int recyclerviewHeight = recyclerView.getHeight(); resizeHeight(recyclerviewHeight); }