Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can we set minimum height of collepsed bottomsheet

I can successfully add peak height but when trying to set minimum height of the bottom sheet, i am unable to do so, and whole sheet got collepsed. so i tried to make it expanded on state hidden but it is not enough for me, as it goes too heigh.

My Main concern is to not hide the bottomsheet any how if get hidden or collapsed it has to reappear and set a minimum height

please suggest something:

below is my code :

final View bottomSheet = findViewById(R.id.bottom_sheet2);
    mBottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
    mBottomSheetBehavior.setHideable(true);
    mBottomSheetBehavior.setPeekHeight(LinearLayout.LayoutParams.MATCH_PARENT);
    mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);

    mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
        @Override
        public void onStateChanged(View bottomSheet, int newState) {
            if (newState == BottomSheetBehavior.STATE_EXPANDED) {

            }
            else if (newState == BottomSheetBehavior.STATE_HIDDEN) {
                mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
            }
            else if (newState == BottomSheetBehavior.STATE_COLLAPSED) {

            }
        }

        @Override
        public void onSlide(View bottomSheet, float slideOffset) {
        }
    });

and hare is my xml:

        <android.support.v4.widget.NestedScrollView
        android:id="@+id/bottom_sheet2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="45dp"
        android:clipToPadding="false"
        android:background="#00ffffff"
        app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:elevation="6dp"
            app:cardCornerRadius="10dp"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"
            android:layout_height="wrap_content">

            <LinearLayout
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:background="#fff"
                android:layout_height="wrap_content">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:layout_margin="10dp">

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="Rohit Lalwani"
                        android:id="@+id/postedBy"
                        android:textSize="16dp"
                        android:padding="10dp"
                        android:textColor="#333"/>

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="Ad posted Yesterday"
                        android:id="@+id/postedTime"
                        android:textSize="13dp"
                        android:padding="10dp"
                        android:textColor="#333"/>
                </LinearLayout>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="1px"
                    android:background="@color/color2"
                    android:layout_marginLeft="15dp"
                    android:layout_marginRight="15dp"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/Price"
                    android:text="₹ 2,00,000"
                    android:padding="15dp"
                    android:textSize="18dp"
                    android:textColor="@color/color1"
                    android:textStyle="bold"
                    android:layout_marginLeft="10dp"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/ProdName"
                    android:text="product name"
                    android:padding="10dp"
                    android:textSize="14dp"
                    android:textColor="#333"
                    android:textStyle="bold"
                    android:layout_marginLeft="15dp"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="1px"
                    android:background="@color/color2"
                    android:layout_marginLeft="15dp"
                    android:layout_marginRight="15dp"/>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="15dp"
                    android:layout_marginLeft="5dp"
                    android:layout_marginRight="5dp"
                    android:orientation="horizontal">

                    <LinearLayout
                        android:layout_width="0px"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:padding="5dp"
                        android:orientation="horizontal">

                        <TextView
                            android:layout_width="0px"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:textSize="16dp"
                            android:textColor="@color/color2"
                            android:id="@+id/cat1Icon"
                            android:text="55"/>

                        <TextView
                            android:layout_width="0px"
                            android:layout_height="wrap_content"
                            android:layout_weight="4"
                            android:textSize="16dp"
                            android:textColor="@color/color2"
                            android:id="@+id/cat1Text"
                            android:text="categeory1"/>

                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="0px"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:padding="5dp"
                        android:orientation="horizontal">

                        <TextView
                            android:layout_width="0px"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:textSize="16dp"
                            android:textColor="@color/color2"
                            android:id="@+id/cat2Icon"
                            android:text="55"/>

                        <TextView
                            android:layout_width="0px"
                            android:layout_height="wrap_content"
                            android:layout_weight="4"
                            android:textSize="16dp"
                            android:textColor="@color/color2"
                            android:id="@+id/cat2Text"
                            android:text="categeory2"/>

                    </LinearLayout>

                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="5dp"
                    android:orientation="horizontal">

                    <LinearLayout
                        android:layout_width="0px"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:padding="5dp"
                        android:orientation="horizontal">

                        <TextView
                            android:layout_width="0px"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:textSize="16dp"
                            android:textColor="@color/color2"
                            android:id="@+id/cat3Icon"
                            android:text="55"/>

                        <TextView
                            android:layout_width="0px"
                            android:layout_height="wrap_content"
                            android:layout_weight="4"
                            android:textSize="16dp"
                            android:textColor="@color/color2"
                            android:id="@+id/cat3Text"
                            android:text="categeory1"/>

                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="0px"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:padding="5dp"
                        android:orientation="horizontal">

                        <TextView
                            android:layout_width="0px"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:textSize="16dp"
                            android:textColor="@color/color2"
                            android:id="@+id/cat4Icon"
                            android:text="55"/>

                        <TextView
                            android:layout_width="0px"
                            android:layout_height="wrap_content"
                            android:layout_weight="4"
                            android:textSize="16dp"
                            android:textColor="@color/color2"
                            android:id="@+id/cat4Text"
                            android:text="categeory2"/>

                    </LinearLayout>

                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="5dp"
                    android:orientation="horizontal">

                    <LinearLayout
                        android:layout_width="0px"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:padding="5dp"
                        android:orientation="horizontal">

                        <TextView
                            android:layout_width="0px"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:textSize="16dp"
                            android:textColor="@color/color2"
                            android:id="@+id/cat5Icon"
                            android:text="55"/>

                        <TextView
                            android:layout_width="0px"
                            android:layout_height="wrap_content"
                            android:layout_weight="4"
                            android:textSize="16dp"
                            android:textColor="@color/color2"
                            android:id="@+id/cat5Text"
                            android:text="categeory1"/>

                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="0px"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:padding="5dp"
                        android:orientation="horizontal">

                        <TextView
                            android:layout_width="0px"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:textSize="16dp"
                            android:textColor="@color/color2"
                            android:id="@+id/cat6Icon"
                            android:text="55"/>

                        <TextView
                            android:layout_width="0px"
                            android:layout_height="wrap_content"
                            android:layout_weight="4"
                            android:textSize="16dp"
                            android:textColor="@color/color2"
                            android:id="@+id/cat6Text"
                            android:text="categeory2"/>

                    </LinearLayout>

                </LinearLayout>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="1px"
                    android:background="@color/color2"
                    android:layout_marginLeft="15dp"
                    android:layout_marginTop="5dp"
                    android:layout_marginRight="15dp"/>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:layout_margin="10dp">

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:textSize="10dp"
                        android:padding="10dp"
                        android:textColor="@color/color2"
                        android:id="@+id/distance"
                        android:text="5 Km away"/>

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:textSize="12dp"
                        android:id="@+id/location"
                        android:textColor="#333"
                        android:padding="10dp"
                        android:text="Alwar, Basant Vihar"/>

                </LinearLayout>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="1px"
                    android:background="@color/color2"
                    android:layout_marginLeft="15dp"
                    android:layout_marginTop="5dp"
                    android:layout_marginRight="15dp"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/description"
                    android:text="Full description about the product"
                    android:padding="10sp"
                    android:layout_margin="5dp"/>

            </LinearLayout>

        </android.support.v7.widget.CardView>
    </android.support.v4.widget.NestedScrollView>
like image 516
Rohit Lalwani Avatar asked Oct 18 '25 21:10

Rohit Lalwani


1 Answers

You just need to define behavior_peekHeight to and behavior_hideable to false as example below:

<android.support.v4.widget.NestedScrollView
android:id="@+id/ores_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="200dp"
app:behavior_hideable="false"
app:behavior_peekHeight="90dp">
like image 190
Ivan Siregar Avatar answered Oct 21 '25 11:10

Ivan Siregar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!