CardView as BottomSheetDialog - PullRequest
       17

CardView as BottomSheetDialog

0 голосов
/ 05 декабря 2018

В приложении, которое я разрабатываю, я бы хотел иметь возможность иметь BottomSheet с прозрачным фоном, с содержимым в CardView, так что просмотр карты накладывается поверх всего, что находится на экране.

Обратите внимание, что теперь, когда я открываю его, фон линейного макета остается серым, поэтому ощущения "плавающего" нет, это просто CardView, нарисованный на сером фоне, а не прозрачный.

Вот код для диалогового окна «Лист»:

<LinearLayout 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="wrap_content"
android:layout_gravity="bottom"
android:background="@android:color/transparent"
android:orientation="vertical">

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/spacing_middle"
    app:cardCornerRadius="3dp"
    app:cardElevation="5dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="@dimen/spacing_smlarge">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="@dimen/spacing_mxlarge"
            android:orientation="horizontal">

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/name"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:text="Place Name"
                    android:textAppearance="@style/TextAppearance.AppCompat.Title"
                    android:textColor="@color/colorPrimary" />

            </LinearLayout>

            <ImageButton
                android:id="@+id/bt_close"
                android:layout_width="@dimen/spacing_mxlarge"
                android:layout_height="@dimen/spacing_mxlarge"
                android:background="?attr/selectableItemBackgroundBorderless"
                android:tint="@color/grey_60"
                app:srcCompat="@drawable/ic_close" />

        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginBottom="@dimen/spacing_middle"
            android:layout_marginTop="@dimen/spacing_middle"
            android:background="@color/colorPrimary" />

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

            <ImageView
                android:id="@+id/horeca_logo"
                android:layout_width="@dimen/spacing_large"
                android:layout_height="wrap_content"
                android:layout_marginEnd="@dimen/spacing_medium"
                android:layout_marginRight="@dimen/spacing_medium"
                android:tint="@color/grey_40"
                app:srcCompat="@drawable/ic_home" />

            <TextView
                android:id="@+id/horeca_type"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:textSize="16dp"
                android:text="Place Type"
                android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
                android:textColor="@color/grey_600" />

        </LinearLayout>

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

            <ImageView
                android:layout_width="@dimen/spacing_large"
                android:layout_height="wrap_content"
                android:layout_marginEnd="@dimen/spacing_medium"
                android:layout_marginRight="@dimen/spacing_medium"
                android:tint="@color/grey_40"
                app:srcCompat="@drawable/ic_location" />

            <TextView
                android:id="@+id/address"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:textSize="16dp"
                android:text="Place Address"
                android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
                android:textColor="@color/grey_600" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="@dimen/spacing_large"
                android:layout_height="wrap_content"
                android:layout_marginEnd="@dimen/spacing_medium"
                android:layout_marginRight="@dimen/spacing_medium"
                android:tint="@color/grey_40"
                app:srcCompat="@drawable/ic_assessment" />

            <android.support.v7.widget.AppCompatRatingBar
                android:id="@+id/horeca_stars"
                style="@style/Yellow.Small.AppCompatRatingBar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:numStars="5"
                android:rating="3.5"
                android:stepSize="0.5"
                android:theme="@style/Yellow.Small.AppCompatRatingBar" />

            <TextView
                android:id="@+id/horeca_rating"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="4.7 (51)"
                android:tint="@color/grey_40" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="@dimen/spacing_large"
                android:layout_height="wrap_content"
                android:layout_marginEnd="@dimen/spacing_medium"
                android:layout_marginRight="@dimen/spacing_medium"
                android:tint="@color/grey_40"
                app:srcCompat="@drawable/ic_clock" />

            <TextView
                android:id="@+id/opening_hours"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:textSize="16dp"
                android:layout_marginTop="8dp"
                android:text="Opening Hours"
                android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
                android:textColor="@color/grey_600" />

            <View
                android:layout_width="80dp"
                android:layout_height="match_parent"/>

            <Button
                android:id="@+id/bt_details"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:layout_marginEnd="5dp"
                android:background="@drawable/custom_button_outlined"
                android:textColor="@color/colorPrimary"
                android:text="Pin'Ups"
                android:textStyle="bold"
                android:theme="@style/Button.Primary" />

        </LinearLayout>


    </LinearLayout>

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

Конструкция должна выглядеть примерно так:

enter image description here

1 Ответ

0 голосов
/ 05 декабря 2018

- добавьте это свойство в тег cardview, оно добавит эффект как тень.

app:cardUseCompatPadding="true"
...