Skip to content

Commit

Permalink
新增切换方法可指定有无动画
Browse files Browse the repository at this point in the history
  • Loading branch information
goweii committed Mar 18, 2020
1 parent c94e01f commit abd2309
Showing 1 changed file with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ private void bringCurrentViewToFront() {
}
}

private void bringFrontView(){
private void bringFrontView() {
if (mChecked) {
mCheckedView.bringToFront();
} else {
Expand Down Expand Up @@ -479,6 +479,36 @@ public void setChecked(boolean checked) {
}
}

/**
* 设置选中状态
*
* @param checked 是否选中
* @param withAnim 是否有动画
*/
public void setChecked(boolean checked, boolean withAnim) {
if (mChecked == checked) return;
mChecked = checked;
onCheckedChanged(mChecked);
if (withAnim && mAnimDuration > 0) {
if (mAnimator != null) {
mAnimator.reverse();
onAnimationReverse();
} else {
mAnimator = createRevealAnim();
mAnimator.start();
}
} else {
if (mAnimator != null) {
mAnimator.cancel();
mAnimator = null;
}
showTwoView();
bringFrontView();
hideBackView();
resetCenter();
}
}

/**
* 切换选中状态,带有动画效果
*/
Expand All @@ -487,7 +517,7 @@ public void toggle() {
setChecked(!mChecked);
}

public void resetCenter(){
public void resetCenter() {
float w = getMeasuredWidth();
float h = getMeasuredHeight();
float l = getPaddingLeft();
Expand Down

0 comments on commit abd2309

Please sign in to comment.