This commit is contained in:
Denis Karmyshakov 2018-10-10 14:14:32 +03:00
parent 5e2d3431dc
commit ca46bc290a
1 changed files with 12 additions and 12 deletions

View File

@ -57,19 +57,9 @@ public class Switcher extends FrameLayout {
final View child = getChildAt(index);
if (child.getId() == id) {
found = true;
if (child.getVisibility() != View.VISIBLE) {
if (ViewCompat.isLaidOut(this) && inAnimation != null) {
child.startAnimation(inAnimation);
}
child.setVisibility(View.VISIBLE);
}
setVisibilityWithAnimation(child, View.VISIBLE);
} else {
if (child.getVisibility() != View.GONE) {
if (ViewCompat.isLaidOut(this) && outAnimation != null) {
child.startAnimation(outAnimation);
}
child.setVisibility(View.GONE);
}
setVisibilityWithAnimation(child, View.GONE);
}
}
if (!found) {
@ -77,4 +67,14 @@ public class Switcher extends FrameLayout {
}
}
private void setVisibilityWithAnimation(@NonNull final View view, final int targetVisibility) {
final Animation animation = targetVisibility == View.VISIBLE ? inAnimation : outAnimation;
if (view.getVisibility() != targetVisibility) {
if (ViewCompat.isLaidOut(this) && animation != null) {
view.startAnimation(animation);
}
view.setVisibility(targetVisibility);
}
}
}