как мы можем установить минимальную высоту свернутого нижнего листа

Я могу успешно добавить высоту пика, но при попытке установить минимальную высоту нижнего листа я не могу этого сделать, и весь лист сжимается. поэтому я попытался сделать его расширенным в скрытом состоянии, но мне этого недостаточно, так как он слишком высок.

Моя главная задача состоит в том, чтобы не скрывать нижний лист, как если бы он был скрыт или свернут, он должен снова появиться и установить минимальную высоту.

пожалуйста, предложите что-нибудь:

ниже мой код:

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) {
        }
    });

и заяц мой 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>

person Rohit Lalwani    schedule 12.08.2017    source источник


Ответы (2)


Вам просто нужно определить для behavior_peekHeight значение false, а для поведения behavior_hideable — значение false, как в примере ниже:

<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">
person Ivan Siregar    schedule 01.06.2018

Попробуйте использовать paddingBottom вместо layout_marginBottom внутри вашего NestedScrollView. Иногда макет лучше понимает интервалы, когда вы используете отступы. Если это не сработает, попробуйте обернуть NestedScrollView в другой вид макета (FrameLayout, LinearLayout и т. д.) и поместите поля или отступы в этот вид. Таким образом, внешний вид всегда будет сохранять минимальную высоту.

person windedmoose    schedule 12.08.2017
comment
я хочу установить минимальную высоту нижнего листа - person Rohit Lalwani; 14.08.2017