Skip to content

Commit abd2309

Browse files
committed
新增切换方法可指定有无动画
1 parent c94e01f commit abd2309

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

reveallayout/src/main/java/per/goweii/reveallayout/RevealLayout.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ private void bringCurrentViewToFront() {
350350
}
351351
}
352352

353-
private void bringFrontView(){
353+
private void bringFrontView() {
354354
if (mChecked) {
355355
mCheckedView.bringToFront();
356356
} else {
@@ -479,6 +479,36 @@ public void setChecked(boolean checked) {
479479
}
480480
}
481481

482+
/**
483+
* 设置选中状态
484+
*
485+
* @param checked 是否选中
486+
* @param withAnim 是否有动画
487+
*/
488+
public void setChecked(boolean checked, boolean withAnim) {
489+
if (mChecked == checked) return;
490+
mChecked = checked;
491+
onCheckedChanged(mChecked);
492+
if (withAnim && mAnimDuration > 0) {
493+
if (mAnimator != null) {
494+
mAnimator.reverse();
495+
onAnimationReverse();
496+
} else {
497+
mAnimator = createRevealAnim();
498+
mAnimator.start();
499+
}
500+
} else {
501+
if (mAnimator != null) {
502+
mAnimator.cancel();
503+
mAnimator = null;
504+
}
505+
showTwoView();
506+
bringFrontView();
507+
hideBackView();
508+
resetCenter();
509+
}
510+
}
511+
482512
/**
483513
* 切换选中状态,带有动画效果
484514
*/
@@ -487,7 +517,7 @@ public void toggle() {
487517
setChecked(!mChecked);
488518
}
489519

490-
public void resetCenter(){
520+
public void resetCenter() {
491521
float w = getMeasuredWidth();
492522
float h = getMeasuredHeight();
493523
float l = getPaddingLeft();

0 commit comments

Comments
 (0)