Skip to content

Commit

Permalink
修复BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
goweii committed Mar 21, 2020
1 parent b56f03d commit b3ca07d
Showing 1 changed file with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -90,7 +91,7 @@ protected void initAttr(AttributeSet attrs) {
/**
* 初始化选中和未选中状态的控件,并设置默认状态
*/
private void initView() {
protected void initView() {
removeAllViews();
if (mCheckedView == null) {
mCheckedView = createCheckedView();
Expand All @@ -102,7 +103,7 @@ private void initView() {
if (checkParams == null) {
checkParams = getDefaultLayoutParams();
}
ViewGroup.LayoutParams uncheckParams = mCheckedView.getLayoutParams();
ViewGroup.LayoutParams uncheckParams = mUncheckedView.getLayoutParams();
if (uncheckParams == null) {
uncheckParams = getDefaultLayoutParams();
}
Expand Down Expand Up @@ -154,29 +155,37 @@ private LayoutParams getDefaultLayoutParams() {
*/
protected View createCheckedView() {
View checkedView;
if (mCheckedLayoutId > 0) {
checkedView = inflate(getContext(), mCheckedLayoutId, null);
if (getCheckedLayoutId() > 0) {
checkedView = LayoutInflater.from(getContext()).inflate(getCheckedLayoutId(), this, false);
} else {
checkedView = new View(getContext());
}
return checkedView;
}

protected int getCheckedLayoutId(){
return mCheckedLayoutId;
}

/**
* 创建非选中状态的控件,子类可复写该方法,初始化自己的控件
*
* @return 非选中状态的控件
*/
protected View createUncheckedView() {
View uncheckedView;
if (mUncheckedLayoutId > 0) {
uncheckedView = inflate(getContext(), mUncheckedLayoutId, null);
if (getUncheckedLayoutId() > 0) {
uncheckedView = LayoutInflater.from(getContext()).inflate(getUncheckedLayoutId(), this, false);
} else {
uncheckedView = new View(getContext());
}
return uncheckedView;
}

protected int getUncheckedLayoutId() {
return mUncheckedLayoutId;
}

@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
Expand Down Expand Up @@ -580,14 +589,14 @@ public void setCheckedView(View checkedView) {
if (checkParams == null) {
checkParams = getDefaultLayoutParams();
}
addView(mCheckedView, getChildCount(), checkParams);
addViewInLayout(mCheckedView, getChildCount(), checkParams);
showTwoView();
bringFrontView();
hideBackView();
}

public void setUncheckedView(View uncheckedView) {
if (mUncheckedView == null) {
if (uncheckedView == null) {
return;
}
if (mUncheckedView == uncheckedView) {
Expand All @@ -599,7 +608,7 @@ public void setUncheckedView(View uncheckedView) {
if (uncheckParams == null) {
uncheckParams = getDefaultLayoutParams();
}
addView(mUncheckedView, getChildCount(), uncheckParams);
addViewInLayout(mUncheckedView, getChildCount(), uncheckParams);
showTwoView();
bringFrontView();
hideBackView();
Expand Down

0 comments on commit b3ca07d

Please sign in to comment.