Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make invisible work #37

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
change: make unvisibale work.
PittyXu committed Oct 26, 2015
commit 28bfb1695e7bf12fd01ce90023c53e3adcbdf12f
Original file line number Diff line number Diff line change
@@ -85,14 +85,38 @@ public void setBorderColor(ColorStateList color) {
updateBackground();
}

private int getLastVisibleIndex() {
for (int i = getChildCount() - 1; i >= 0; i--) {
if (getChildAt(i).getVisibility() == VISIBLE) {
return i;
}
}
return 0;
}

private int getFirstVisibleIndex() {
int count = getChildCount();
for (int i = 0; i < count; i++) {
if (getChildAt(i).getVisibility() == VISIBLE) {
return i;
}
}
return count - 1;
}

public void updateBackground() {
int count = super.getChildCount();
int lastVisible = getLastVisibleIndex();

for (int i = 0; i < count; i++) {
View child = getChildAt(i);
updateBackground(child);
if (child.getVisibility() == VISIBLE) {
updateBackground(child);
}

// If this is the last view, don't set LayoutParams
if (i == count - 1) break;
if (i == lastVisible)
break;

LayoutParams initParams = (LayoutParams) child.getLayoutParams();
LayoutParams params = new LayoutParams(initParams.width, initParams.height, initParams.weight);
@@ -195,9 +219,9 @@ private void setChildRadii(int newChildren, int newChild) {
// if there is only one child provide the default radio button
if (children == 1) {
radii = rDefault;
} else if (child == 0) { //left or top
} else if (child == getFirstVisibleIndex()) { //left or top
radii = (getOrientation() == LinearLayout.HORIZONTAL) ? rLeft : rTop;
} else if (child == children - 1) { //right or bottom
} else if (child == getLastVisibleIndex()) { //right or bottom
radii = (getOrientation() == LinearLayout.HORIZONTAL) ? rRight : rBot;
} else { //middle
radii = rMiddle;