Material Cardview - 孩子们没有被剪掉<原料药 28 [英] Material Cardview - Children not getting clipped < API 28

查看:22
本文介绍了Material Cardview - 孩子们没有被剪掉<原料药 28的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将嵌套滚动视图放入带圆角的材料卡视图并滚动时,会出现一个错误,即其他材料卡视图不会被剪裁,并且边缘会溢出圆角.文本视图和 viewpager 对象的角落被剪得很好.此错误出现在 api 28 及更低版本上.

When putting a nested scroll view inside a material card view with rounded corners and scrolling there is a bug where other material card views dont get clipped and there edges spill over the rounded corners. Text views and viewpager objects got there corners clipped fine. This bug appears on api 28 and below.

有没有人知道解决这个问题的方法?

Does anyone know a work around for this?

 <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 及以下

Constraint layout > Material card view (main container) > Nested Scroll View > Additional material card views (enough to scroll) & API 28 and below

推荐答案

在 Cardview 中,在 xml 中添加属性:

In your Cardview, add the property in your xml:

cardPreventCornerOverlap="false"

这篇关于Material Cardview - 孩子们没有被剪掉&lt;原料药 28的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆