gpt4 book ai didi

android - Bottom Sheet 错误 : The view is not a child of CoordinatorLayout

转载 作者:行者123 更新时间:2023-12-02 16:11:09 24 4
gpt4 key购买 nike

我想创建一个布局,其中 80% 的屏幕包含单独的布局,20% 的屏幕垂直包含 Bottom Sheet 。但是当我尝试这样做时,它给了我错误“该 View 不是 CoordinatorLayout 的子级”。我收到错误,但我想不出其他方法来做到这一点。有人可以帮助我实现它吗?帮助将不胜感激。

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#efefef">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="5">

<include
layout="@layout/content_main_new"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4" />

<include
layout="@layout/content_bottom_sheet2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />

</LinearLayout>

</android.support.design.widget.CoordinatorLayout>

content_bottom_sheet2.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/bottomSheetLayout"
android:layout_width="match_parent"
android:layout_height="230dp"
android:background="@color/colorPrimary"
android:orientation="vertical"
android:padding="@dimen/activity_vertical_margin"
app:behavior_peekHeight="90dp"
app:layout_behavior="@string/bottom_sheet_behavior">

<!--android:background="@android:color/holo_orange_light"-->

<android.support.v7.widget.CardView
android:id="@+id/cvBottomCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="@dimen/spIconsize"
android:visibility="visible"
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="10dp"
app:cardElevation="5dp">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout

android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:paddingTop="10dp"

android:orientation="horizontal">

<Button
android:layout_marginBottom="5dp"
android:id="@+id/btnReview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:layout_weight="1"
android:background="@drawable/rounded_button_darkgreen_bg"
android:text="Review"
android:textColor="@color/white" />

<Button
android:layout_marginBottom="5dp"
android:id="@+id/btnReschedule"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_weight="1"
android:background="@drawable/rounded_button_grey"
android:text="Reschedule"
android:textColor="@color/white" />
</LinearLayout>


<RelativeLayout
android:id="@+id/relLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/linearLayout"
android:layout_marginTop="5dp"
android:padding="10dp"
android:visibility="visible">

<ImageButton
android:id="@+id/imageButton"
android:layout_width="80dp"
android:layout_height="90dp"
android:src="@drawable/user"
android:visibility="gone" />

<TextView
android:id="@+id/tvappointmentId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/imageButton"
android:text="Appointment ID - 5727"
android:textColor="@color/black" />

<TextView
android:id="@+id/tvCustomerName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvappointmentId"
android:layout_toEndOf="@+id/imageButton"
android:text="Name - Virat Sharma"
android:textColor="@color/black" />

<TextView
android:id="@+id/tvLoanType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvCustomerName"
android:layout_toEndOf="@+id/imageButton"
android:text="Loan Type - Home LOAN" />

<TextView
android:id="@+id/tvLoanAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvLoanType"
android:layout_toEndOf="@+id/imageButton"
android:text="Loan Amount - 5727" />

<TextView
android:id="@+id/tvTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/tvappointmentId"
android:layout_alignBottom="@+id/tvappointmentId"
android:layout_alignParentEnd="true"
android:gravity="right"
android:text="01:22 Mins"
android:textColor="@color/red_error"
android:textStyle="bold"
android:visibility="gone" />

</RelativeLayout>

</RelativeLayout>
</android.support.v7.widget.CardView>

</LinearLayout>
</android.support.design.widget.CoordinatorLayout>

最佳答案

你可以试试这个方法吗?


<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/bottomSheetLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:behavior_peekHeight="90dp"
app:layout_behavior="@string/bottom_sheet_behavior">


<LinearLayout
android:layout_width="match_parent"
android:layout_height="230dp"
android:background="@color/colorPrimary"
android:orientation="vertical"
android:padding="@dimen/activity_vertical_margin">
...
</LinearLayout>

</android.support.design.widget.CoordinatorLayout>

我所做的就是将您稍后将调用的 id 作为根元素中的 Bottom Sheet (顺便说一下,如果您愿意,可以是 ConstraintLayout),正如您所注意到的,该根的父级元素将自动成为 CoodinatorLayout。第二件事是将此元素的高度设置为wrap_content布局行为也应该位于根元素中。 app:layout_behavior="@string/bottom_sheet_behavior"

关于android - Bottom Sheet 错误 : The view is not a child of CoordinatorLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51099663/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com