【问题标题】:How to remove white space from BottomSheetDialog when adding a fake shadow?添加假阴影时如何从BottomSheetDialog中删除空白?
【发布时间】:2020-11-19 01:12:53
【问题描述】:

我正在使用这个 SO 答案来模拟我的 BottomSheetDialogFragment 上的高度,因为高度不适用于它。

https://stackoverflow.com/a/40927770/11110509

但是,当我添加那个假阴影时,会出现与 SO 答案不同的不需要的空白。如何删除它?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:elevation="6dp">

    <View
        android:id="@+id/fragplaces_top_shadow"
        android:layout_width="match_parent"
        android:layout_height="16dp"
        android:background="@drawable/shadow_dialog_places_top"/>

    <TextView
        android:id="@+id/fragplaces_app_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Places near me"
        android:textColor="@color/colorWhite"
        android:textStyle="bold"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/fragplaces_top_shadow"
        android:paddingStart="12dp"
        android:paddingEnd="12dp"
        android:paddingTop="16dp"
        android:paddingBottom="16dp"
        android:background="@color/standardBlue"/>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/fragadd_recycler"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/fragplaces_app_name"
        android:background="@color/colorWhite"/>

</RelativeLayout>

这是人造阴影:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:angle="90"
        android:endColor="@android:color/transparent"
        android:startColor="#64000000"/>
</shape>

向父布局添加透明背景也不起作用:

android:background="@android:color/transparent"

如何去除假阴影中不需要的空白区域?

【问题讨论】:

    标签: android material-design bottom-sheet android-bottomsheetdialog


    【解决方案1】:

    在您的对话框设置中,尝试将背景设置为透明:

    View view = View.inflate(getContext(), R.layout.fragment_bottom_sheet, null);
    dialog.setContentView(view);
    
    ( (View) view.getParent()).setBackgroundColor(Color.TRANSPARENT);
    

    请注意,您将其应用于视图而不是对话框。

    【讨论】:

      【解决方案2】:

      简单的破解

      您可以将android:layout_marginTop="-5dp"(或-3dp 到-5dp)给View (fragplaces_top_shadow)

      【讨论】:

        猜你喜欢
        • 2021-05-07
        • 1970-01-01
        • 2010-10-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-15
        相关资源
        最近更新 更多