<LinearLayout android:id="@+id/shopping_card" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="@dimen/dp_77" app:behavior_hideable="true" app:behavior_peekHeight="50dp" app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" android:background="@drawable/shape_picture_bg" android:orientation="vertical"> Caused by: java.lang.IllegalArgumentException: The view is not a child of CoordinatorLayout
时间: 2024-04-28 09:20:02 浏览: 16
这个错误通常是因为在使用 BottomSheetBehavior 时,将一个不是 CoordinatorLayout 的 View 作为其子 View 添加时引起的。要解决这个问题,可以将子 View 改为 CoordinatorLayout 的子 View,或者将 BottomSheetBehavior 应用到 CoordinatorLayout 上的子 View 上。具体可以参考 BottomSheetBehavior 的使用文档。
相关问题
<LinearLayout android:layout_width="match_parent" android:layout_height="50dp" android:gravity="center" android:background="@color/colorPrimary"> <item android:id="@+id/menu_icon" android:icon="@drawable/wut" android:title="Icon" android:showAsAction="always"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/colorWhite" android:textSize="16dp" android:text="登录"/> </LinearLayout>我这样编写对吗?
这段代码是用于实现一个带有图标和文本的菜单项,但是缺少一些必要的属性和标签。可以参考以下代码进行修改:
```
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_icon"
android:title="Icon"
android:icon="@drawable/wut"
android:showAsAction="always" />
</menu>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
android:background="@color/colorPrimary">
<ImageView
android:id="@+id/menu_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/wut" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorWhite"
android:textSize="16dp"
android:text="登录" />
</LinearLayout>
```
其中,第一个代码块是菜单项的布局,第二个代码块是菜单项所在的LinearLayout的布局。需要注意的是,菜单项的id不能和LinearLayout的id相同,需要进行修改。
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="30dp" android:orientation="horizontal"> <TextView android:id="@+id/tv1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="时间:" android:textSize="20dp"/> <EditText android:id="@+id/ed_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入预约时间" android:textSize="20dp" /> </LinearLayout> 布局超过app的界面 如何调整实现下滑能看到超过的内容
你可以将布局包裹在一个 ScrollView 中,这样用户就可以通过滑动来查看超出屏幕的部分。修改后的代码如下:
```
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:orientation="horizontal">
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="时间:"
android:textSize="20dp"/>
<EditText
android:id="@+id/ed_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入预约时间"
android:textSize="20dp"
/>
</LinearLayout>
</ScrollView>
```
这样就可以通过滑动来查看超出屏幕的部分。