2

I am trying to include my bottom_sheet.xml file into my activity activity_main.xml file. I am trying to achieve this by using <include layout="@layout/bottom_sheet"/>

However, the bottom sheet isn't showing in my activity_main.xml file.

Code of activity_main.xml file:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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"
    tools:context=".MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/Theme.FaceDetector.AppBarOverlay">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/Theme.FaceDetector.PopupOverlay" />

    </com.google.android.material.appbar.AppBarLayout>

    <include layout="@layout/content_main" />
    <include layout="@layout/bottom_sheet"/>


</androidx.coordinatorlayout.widget.CoordinatorLayout>

Code of bottom_sheet.xml file:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    app:behavior_hideable="false"
    app:behavior_peekHeight="74dp"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior">


    <View
        android:id="@+id/view"
        android:layout_width="0dp"
        android:layout_height="2dp"
        android:background="@android:color/darker_gray"
        app:layout_constraintBottom_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <FrameLayout
        android:id="@+id/bottom_sheet_button"
        android:layout_width="0dp"
        android:layout_height="56dp"
        android:layout_margin="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:background="@color/colorPrimary"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/view">

        <ImageView
            android:id="@+id/bottom_sheet_button_img"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:src="@android:drawable/ic_menu_camera" />

        <ProgressBar
            android:id="@+id/bottom_sheet_butotn_progress_bar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:visibility="gone" />


    </FrameLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/bottom_sheet_recycler_view"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/view" />
</androidx.constraintlayout.widget.ConstraintLayout>

Picture of result:

enter image description here

Thanks!

CodingChap
  • 1,088
  • 2
  • 10
  • 23

1 Answers1

0

Change your include tag for the bottom_sheet like below in the activity_main.xml

by adding the attribut app:layout_behavior and other attributes of the bottom_sheet into the include tag and specify the width and height to your include tag

 <include
        layout="@layout/bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:behavior_hideable="false"
        app:behavior_peekHeight="74dp"
        app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" />

And remove unnecessary attributes from the bottom_sheet.xml :

app:behavior_hideable=""
app:behavior_peekHeight=""
app:layout_behavior="" 

So you need to add all the bottom_sheet attributs inside the include tag not on the layout

Shay Kin
  • 2,539
  • 3
  • 15
  • 22
  • Hi, thank you for your answer. However, moving the attributes didn't work for me. After researching a little more, I found this which answered my question: https://stackoverflow.com/questions/51617186/bottomsheetbehavior-not-in-androidx-libraries – CodingChap Apr 17 '21 at 01:48
  • Yes I did not notice app:layoout_behavior sory bro good luck for the flowing for me im using the material library – Shay Kin Apr 17 '21 at 02:00
  • 1
    @CodingChap My answer may be helpful when you set `app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"` And not `"android.support.design.widget.BottomSheetBehavior"` – Shay Kin Apr 17 '21 at 02:06
  • 1
    Hi, thanks. I changed that as well before, but I don't think it makes a difference if I move the attributes to the include tag rather than the layout. Both ways work for me. – CodingChap Apr 17 '21 at 03:51
  • 1
    Well, maybe if others have the same problem as you, it could be useful as the other post doesn't discuss this. – CodingChap Apr 17 '21 at 06:09