BottomSheetBehavior之java.lang.IllegalArgumentException:TheviewisnotassociatedwithBottomSheetBehavior

wei-spring發表於2016-09-14

 

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的時候才是正確的.


相關文章