Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions badgeviewlib/src/main/java/q/rorbin/badgeview/QBadgeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是不是可以直接去掉 instanceof 的判断,把新增的 BadgeContainer id 直接变成原来 targetView 的 id

badgeContainer.setId(targetView.getId());
}
targetContainer.addView(badgeContainer, index, targetParams);
Expand Down Expand Up @@ -832,7 +832,7 @@ private class BadgeContainer extends ViewGroup {

@Override
protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) {
if(!(getParent() instanceof RelativeLayout)){
if (!(getParent() instanceof RelativeLayout)) {
super.dispatchRestoreInstanceState(container);
}
}
Expand Down Expand Up @@ -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;
}
}
}