CardView为BottomSheetDialog

时间:2018-12-04 22:49:07

标签: android background transparency floating

在我设计的应用程序中,我希望能够带BottomSheet透明背景,内容放在CardView中,以使Cardview覆盖屏幕上的任何内容。

请注意,现在每当我打开它时,linearlayout的背景仍然是灰色的,因此没有“浮动”的感觉,它只是在灰色背景上绘制的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 :(得分:0)

-将此属性添加到cardview标记中,将增加阴影效果。     

app:cardUseCompatPadding="true"