From 2a8f1b3635a20da1396c1f6e678e9dea51bbbe1c Mon Sep 17 00:00:00 2001 From: xiayong Date: Thu, 23 Aug 2018 15:28:51 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=9C=A8RelativeLayout?= =?UTF-8?q?=E7=AD=89=E4=BE=9D=E8=B5=96view=20id=E7=9A=84=E5=B8=83=E5=B1=80?= =?UTF-8?q?=E4=B8=ADfindViewById=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/q/rorbin/badgeview/QBadgeView.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/badgeviewlib/src/main/java/q/rorbin/badgeview/QBadgeView.java b/badgeviewlib/src/main/java/q/rorbin/badgeview/QBadgeView.java index c96a30f..ee6fb22 100644 --- a/badgeviewlib/src/main/java/q/rorbin/badgeview/QBadgeView.java +++ b/badgeviewlib/src/main/java/q/rorbin/badgeview/QBadgeView.java @@ -155,7 +155,7 @@ public Badge bindTarget(final View targetView) { ViewGroup.LayoutParams targetParams = targetView.getLayoutParams(); targetContainer.removeView(targetView); final BadgeContainer badgeContainer = new BadgeContainer(getContext()); - if(targetContainer instanceof RelativeLayout){ + if (targetContainer instanceof RelativeLayout) { badgeContainer.setId(targetView.getId()); } targetContainer.addView(badgeContainer, index, targetParams); @@ -832,7 +832,7 @@ private class BadgeContainer extends ViewGroup { @Override protected void dispatchRestoreInstanceState(SparseArray container) { - if(!(getParent() instanceof RelativeLayout)){ + if (!(getParent() instanceof RelativeLayout)) { super.dispatchRestoreInstanceState(container); } } @@ -871,5 +871,21 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension(targetView.getMeasuredWidth(), targetView.getMeasuredHeight()); } } + + protected View findViewTraversal(int id) { + + final int len = getChildCount(); + + for (int i = 0; i < len; i++) { + View v = getChildAt(i); + v = v.findViewById(id); + + if (v != null) { + return v; + } + } + + return null; + } } }