有人可以解释这个异常何时发生?
12-18 11:20:07.225 15944-15944/com.test.dev.debug E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.dev.debug, PID: 15944
java.lang.IllegalArgumentException: Illegal state argument: 5
at android.support.design.widget.BottomSheetBehavior.startSettlingAnimation(BottomSheetBehavior.java:631)
at android.support.design.widget.BottomSheetBehavior$1.run(BottomSheetBehavior.java:550)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
Java类
public class BottomSheetController {
private BottomSheetBehavior<View> bottomSheetBehavior;
private WeakReference<FrameLayout> bottomSheetContainer;
private Slide slide;
public interface Slide {
void onSlide(@NonNull View bottomSheet, float slideOffset);
}
public void bind(FrameLayout bottomSheetContainer) {
this.bottomSheetContainer = new WeakReference<>(bottomSheetContainer);
bottomSheetBehavior = BottomSheetBehavior.from(this.bottomSheetContainer.get());
bottomSheetBehavior.setHideable(true);
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
bottomSheetBehavior.setBottomSheetCallback(sheetCallback());
}
public void unbind() {
this.bottomSheetContainer.clear();
}
public void setSlide(Slide slide) {
this.slide = slide;
}
public void collapse() {
bottomSheetBehavior.setHideable(true);
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
public void expand() {
bottomSheetBehavior.setHideable(false);
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
public void hide() {
bottomSheetBehavior.setHideable(true);
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
}
public int getState() {
return bottomSheetBehavior.getState();
}
private BottomSheetBehavior.BottomSheetCallback sheetCallback() {
return new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
if (newState != BottomSheetBehavior.STATE_HIDDEN) {
bottomSheetBehavior.setHideable(false);
} else {
bottomSheetBehavior.setHideable(true);
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
if (slide != null) {
slide.onSlide(bottomSheet, slideOffset);
}
}
};
}
}
public class IllegalArgumentException extends RuntimeException
抛出以指示方法已被传递非法或不适当的参数。
在代码中的某处,您将非法参数传递给方法startSettlingAnimation()(BottomSheetBehavior类)。此方法抛出异常:
void startSettlingAnimation(View child, int state) {
int top;
if (state == STATE_COLLAPSED) {
top = mCollapsedOffset;
} else if (state == STATE_HALF_EXPANDED) {
top = mHalfExpandedOffset;
} else if (state == STATE_EXPANDED) {
top = getExpandedOffset();
} else if (mHideable && state == STATE_HIDDEN) {
top = mParentHeight;
} else {
throw new IllegalArgumentException("Illegal state argument: " + state);
}
if (mViewDragHelper.smoothSlideViewTo(child, child.getLeft(), top)) {
setStateInternal(STATE_SETTLING);
ViewCompat.postOnAnimation(child, new SettleRunnable(child, state));
} else {
setStateInternal(state);
}
}
你的错误是:Illegal state argument: 5
。 5是STATE_HIDDEN
的int值。所以当你的状态是STATE_HIDDEN
(5)时,你的mHideable
布尔值是假的。所以,基本的建议是设置mHidable = true;
没有任何代码,这就像我可以告诉你的那样。