小编Chr*_*ano的帖子

java.lang.IllegalArgumentException:视图与BottomSheetBehavior无关

我知道之前已经问过,但即使我检查了答案,我也没有找到解决我具体问题的方法:

我创建了一个预期充当底层的布局:

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/btmsht"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
android:orientation="vertical"
android:layout_height= "300dp"
android:layout_width="match_parent"
tools:showIn="@layout/activity_principal">
Run Code Online (Sandbox Code Playgroud)

我在协调器布局中使用它:

<include layout="@layout/btmsht_principal" android:layout_width="match_parent"
    android:layout_height="match_parent"/>
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试获取参考时:

View tview = findViewById(R.id.btmsht);
    btmsht = BottomSheetBehavior.from(tview);
Run Code Online (Sandbox Code Playgroud)

我收到错误:

java.lang.IllegalArgumentException: The view is not associated with BottomSheetBehavior
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
        at android.app.ActivityThread.access$800(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5254)
        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:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.IllegalArgumentException: The view is not associated with BottomSheetBehavior
        at android.support.design.widget.BottomSheetBehavior.from(BottomSheetBehavior.java:816)
        at com.blixter.fiesta.Principal.creacionViews(Principal.java:69)
        at com.blixter.fiesta.Principal.onCreate(Principal.java:57)
        at android.app.Activity.performCreate(Activity.java:5990)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
        at …
Run Code Online (Sandbox Code Playgroud)

android bottom-sheet

4
推荐指数
1
解决办法
4899
查看次数

标签 统计

android ×1

bottom-sheet ×1