材料设计卡片视图 - API 28以下子视图未被剪切

3
当将嵌套滚动视图放置在具有圆角和滚动的材料卡片视图中时,存在一个错误,其他材料卡片视图不会被剪裁,其边缘会溢出圆角。文本视图和viewpager对象会被正确剪裁。此错误会出现在api28及以下版本。有人知道解决方法吗?

Not clipped API 28 <

Clipps API29 >

 <androidx.constraintlayout.widget.ConstraintLayout  xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_workout_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="framework.presentation.workouts.WorkoutFragment"
>

<com.google.android.material.appbar.AppBarLayout
    android:id="@+id/app_bar_workout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:contentInsetStart="0dp"
    app:elevation="0dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <include
        android:id="@+id/toolbar_workout_navigation"
        layout="@layout/toolbar_home" />

</com.google.android.material.appbar.AppBarLayout>

<com.google.android.material.card.MaterialCardView
    style="@style/cv_style_all_rounded"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_marginBottom="@dimen/cv_margin_bottom"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/app_bar_workout"
    app:strokeColor="@color/dividerColor"
    app:strokeWidth="0.5dp">

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:overScrollMode="never"
        >

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/home_header_image"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/home_header" />

            <com.google.android.material.textview.MaterialTextView
                android:id="@+id/home_title"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="32dp"
                android:layout_marginTop="@dimen/header_margin_top"
                android:layout_marginEnd="32dp"
                android:gravity="center"
                android:text="@string/home_title"
                android:textSize="?attr/textAppearanceHeadline5"
                android:textStyle="bold"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/home_header_image" />

            <com.google.android.material.textview.MaterialTextView
                android:id="@+id/home_description"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="32dp"
                android:layout_marginTop="@dimen/description_margin_top"
                android:layout_marginEnd="32dp"
                android:gravity="center"
                android:text="@string/home_description"
                android:textSize="?attr/textAppearanceHeadline6"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/home_title" />

            <View
                android:id="@+id/divider_home"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                  android:layout_marginStart="@dimen/workout_intro_left_right_margin"
                android:layout_marginTop="@dimen/divider_margin_top"
                android:layout_marginEnd="@dimen/workout_intro_left_right_margin"
                android:background="?android:attr/dividerVertical"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/home_description" />

            <androidx.viewpager2.widget.ViewPager2
                android:id="@+id/quotesViewPager2"
                android:layout_width="0dp"
                android:layout_height="150dp"
                android:layout_marginStart="@dimen/start_end_padding"
                android:layout_marginTop="32dp"
                android:layout_marginEnd="@dimen/start_end_padding"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/divider_home" />

            <com.google.android.material.textview.MaterialTextView
                android:id="@+id/tvFeaturedVideo"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginTop="32dp"
                android:layout_marginEnd="16dp"
                android:text="@string/featured_video"
                android:textSize="?attr/textAppearanceHeadline6"
                android:textStyle="bold"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/quotesViewPager2" />

            <com.google.android.material.card.MaterialCardView
                android:id="@+id/cvFeaturedVideo"
                style="@style/cv_style_home_layout"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_marginStart="@dimen/start_end_padding"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="@dimen/start_end_padding"
                android:clipChildren="true"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/tvFeaturedVideo">

                <androidx.constraintlayout.widget.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <ImageView
                        android:id="@+id/featuredThumbNail"
                        android:layout_width="0dp"
                        android:layout_height="210dp"
                        android:layout_marginBottom="12dp"
                        android:adjustViewBounds="false"
                        android:scaleType="centerCrop"
                        app:layout_constraintBottom_toTopOf="@+id/featuredVideoTitle"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />

                    <TextView
                        android:id="@+id/featuredVideoTitle"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="32dp"
                        android:layout_marginEnd="32dp"
                        android:layout_marginBottom="12dp"
                        android:maxLines="1"
                        android:text="TextView"
                        android:textAlignment="center"
                        android:textSize="18sp"
                        android:textStyle="bold"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintHorizontal_bias="0.0"
                        app:layout_constraintStart_toStartOf="parent" />

                    <ImageView
                        android:id="@+id/youtubeIcon"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        app:layout_constraintBottom_toBottomOf="@+id/featuredThumbNail"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent"
                        app:srcCompat="@drawable/youtube_logo_icon_150px" />
                </androidx.constraintlayout.widget.ConstraintLayout>
            </com.google.android.material.card.MaterialCardView>

重现步骤:

约束布局 > 材料卡视图(主容器)> 嵌套滚动视图 > 其他材料卡视图(足够滚动)& API 28及以下版本


添加您的 XML 代码。 - iamanbansal
添加了一些内容,但是太大了,不能全部发送。你只需要一个大小与屏幕相同的 Material cardview。将圆角半径设置为50dp。在其中嵌套一个滚动视图。然后放置一堆嵌套的 Material cardview,在父卡片视图内滚动足够多的次数。在 API 28 或以下版本上加载模拟器,你会发现当滚动时,圆角不会被裁剪。 - AndroidDev123
嗨,为什么你将内部的MaterialCardView高度设置为match_parent..这似乎会与外部的MaterialCardView重叠。 - Zain
@Zain 我已将其更改为包裹内容,但没有任何效果。 - AndroidDev123
API 28 对于这个 bug 来说是一个奇怪的门槛。你能发布一下你的 cv_style_home_layout 样式吗?你在 v28 资源目录中有多个版本吗?可能有一些属性导致了这个问题。或者,你可以使用带有高度和圆角矩形背景的普通 View,并使用 clipToOutline。现在除非你支持 pre-lollipop,否则 CardView 真的不是必要的。 - Jschools
显示剩余2条评论
1个回答

0
在您的 CardView 中,在您的 XML 中添加以下属性:
cardPreventCornerOverlap="false"

不幸的是,这没有任何效果。 - AndroidDev123
这个重叠现象是在Android Studio的预览页面上显示还是也在手机上显示? - Harsh0021
模拟器和手机 - AndroidDev123
尝试使用 androidx.cardview.widget.CardView 替代 com.google.android.material.card.MaterialCardView,并将 app:cardPreventCornerOverlap="true" 添加为属性。 - Monim Kaiser
很遗憾,没有任何效果。 - AndroidDev123

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接