AndroidRuntime: FATAL EXCEPTION: main Process: me.chunsheng.uberdriver, PID: 13674 java.lang.RuntimeException: Unable to start activity ComponentInfo{me.chunsheng.uberdriver/me.chunsheng.uberdriver.MainActivity}: java.lang.IllegalArgumentException: The view is not associated with BottomSheetBehavior at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2503) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2570) at android.app.ActivityThread.access$800(ActivityThread.java:162) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1446) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5528) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:952) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747) Caused by: java.lang.IllegalArgumentException: The view is not associated with BottomSheetBehavior at android.support.design.widget.BottomSheetBehavior.from(BottomSheetBehavior.java:710) at me.chunsheng.uberdriver.MainActivity.onCreate(MainActivity.java:27) at android.app.Activity.performCreate(Activity.java:6074) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1117) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2456) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2570) at android.app.ActivityThread.access$800(ActivityThread.java:162) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1446) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5528) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:952) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747) 09-14 22:52:58.951 13674-13674/me.chunsheng.uberdriver I/Process: Sending signal. PID: 13674 SIG: 9
错误信息如上:view与BottomSheetBehavior不匹配???
这是什么鬼呢???
由于BottomSheetBehavior填充的view需要为 android.support.design.widget.CoordinatorLayout 的一个子view,这时候,比如view在布局中为一个相对布局,需要这样写:
<RelativeLayout
android:id="@+id/layout_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="@android:color/white"
android:elevation="8dp"
app:behavior_hideable="true"
app:behavior_peekHeight="90dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<TextView
android:id="@+id/text_view_sheet_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/activity_vertical_margin"
android:text="点击叫车,上滑选车"
android:textSize="14sp" />
</RelativeLayout>
注意红色声明,这时候用BottomSheetBehavior填充这个view的时候才是正确的.