如何修复 Android CardView 不透明度错误

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

CardView 将使白色背景不透明,以便背景可见。这里还需要阴影效果。然而,随着高程值的增加,卡片视图的背景变得奇怪。有什么办法可以解决这个问题吗??

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#BEBEBE"
        >
        <androidx.appcompat.widget.AppCompatImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintTop_toTopOf="@id/cardView"
            app:layout_constraintStart_toStartOf="@id/cardView"
            app:layout_constraintEnd_toEndOf="@id/cardView"
            app:layout_constraintBottom_toBottomOf="@id/cardView"
            android:src="@drawable/ic_launcher_background"
            />
        <com.google.android.material.card.MaterialCardView
            android:id="@+id/cardView"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            android:layout_marginHorizontal="30dp"
            app:cardElevation="10dp"
            app:cardBackgroundColor="#99FFFFFF"
            >

            <androidx.appcompat.widget.LinearLayoutCompat
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:orientation="vertical"
                android:gravity="center"
                >
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="sample"
                    />

            </androidx.appcompat.widget.LinearLayoutCompat>

        </com.google.android.material.card.MaterialCardView>

    </androidx.constraintlayout.widget.ConstraintLayout>

有什么办法可以解决这个问题吗??

android opacity cardview elevation
1个回答
0
投票

使用 Android 提供的材料组件会带来一定的副作用。所有这些影响都在 AndroidMaterial Design 网站上得到了很好的记录,但基本上您在这里看到的是,材料卡经过预编程,可以随着海拔的增加而改变其颜色的色调,如下所示给屏幕一种“深度”感。

话虽如此,我不建议您使用透明卡,因为这不是它们的预期用途。如果您需要创建任何类型的透明表面,请考虑使用常规视图,并分别从

CardView
添加您需要的所有属性;例如,圆角、标高等

使用 Material 组件时,重要的是要了解每个组件的预期用途,并熟悉所有这些“副作用”(我称之为“副作用”),这些副作用更多的是功能而不是意外情况。

© www.soinside.com 2019 - 2024. All rights reserved.