ImageView 覆盖 BottomSheetDialogFragment 的圆角

问题描述 投票:0回答:1

BottomSheetDialog 通过使用下面的代码从顶部开始舍入..

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(STYLE_NORMAL, R.style.BottomSheetDialogTheme)
    }

style.xml

<style name="BottomSheetDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
        <item name="bottomSheetStyle">@style/BottomSheetModalStyle</item>
    </style>

    <style name="BottomSheetModalStyle" parent="Widget.Design.BottomSheet.Modal">
        <item name="android:background">@drawable/selector_top_rounded_corner</item>
    </style>

selector_top_rounded_corner.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@android:color/white" />
    <corners
        android:topLeftRadius="16dp"
        android:topRightRadius="16dp" />

</shape>

BottomSheetDialogFragment 的布局顶部添加 imageView 后。顶部的圆度消失了,顶部的背景是平坦的。

这个形状变成圆形,但在其顶部添加图像后会覆盖(取消)背景效果并从顶部变得平坦。

其中ImageView属性如下。

<androidx.appcompat.widget.AppCompatImageView
                android:id="@+id/imageViewPhoto"
                android:layout_width="match_parent"
                android:minHeight="200dp"
                android:layout_height="160dp"
                android:scaleType="center"
                app:layout_constraintDimensionRatio="h,375:240"
                app:layout_constraintTop_toTopOf="parent" />
android rounded-corners android-bottomsheetdialog
1个回答
0
投票

ImageView 有自己的背景,默认情况下是一个矩形,它覆盖了底部工作表的圆角。

你可以尝试将ImageView设置为相同的圆形背景

<androidx.appcompat.widget.AppCompatImageView
    ...
    android:background="@drawable/selector_top_rounded_corner" />
© www.soinside.com 2019 - 2024. All rights reserved.