CardView如何实现背景模糊和透明?Android Studio

6

我试图制作这个效果:

enter image description here

但是我得到的是这个效果:

enter image description here

我不能把背景同时变成模糊和透明,有什么方法可以实现吗?

当我使用 "alpha" 时,文本的不透明度也被去除了,而在原始照片中没有发生这种情况。

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/tools"
    android:fitsSystemWindows="true">

    <androidx.cardview.widget.CardView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:cardCornerRadius="10dp"
        android:layout_gravity="center|top"
        android:layout_margin="8dp"
        card_view:cardElevation="0dp">

        <androidx.cardview.widget.CardView
            android:layout_width="180dp"
            android:layout_height="wrap_content"
            app:cardCornerRadius="2dp"
            android:layout_gravity="top"
            android:layout_marginTop="130dp"
            android:layout_marginStart="50dp"
            card_view:cardBackgroundColor="@android:color/transparent"
            card_view:cardElevation="10dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="For example"
                android:layout_gravity="center"
                android:textColor="@color/colorAccent"
                android:textStyle="bold" />
        </androidx.cardview.widget.CardView>
        

        <LinearLayout
            android:layout_width="280dp"
            android:layout_height="180dp"
            android:orientation="vertical">
            

            <ImageView
                android:id="@+id/image"
                android:layout_width="match_parent"
                android:layout_height="180dp"
                android:src="@drawable/imagen1"
                android:scaleType="centerCrop"/>
            
        </LinearLayout>

    </androidx.cardview.widget.CardView>
    
</androidx.coordinatorlayout.widget.CoordinatorLayout>
1个回答

1
你需要在 Card View 中使用 BlurKit 布局。请按照以下方式更改您的 Card View 内容。
   <androidx.cardview.widget.CardView
    android:id="@+id/spdv_details_cv"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:cardCornerRadius="20dp"
    app:cardElevation="0dp"

    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:cardBackgroundColor="#23FFFFFF"
    app:layout_constraintHeight_percent="0.5"
    android:layout_margin="20dp"
    >
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <io.alterac.blurkit.BlurLayout
        android:id="@+id/blurLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        
        app:blk_blurRadius="1"

        app:blk_fps="1" />
    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >



        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="20dp"
            android:background="@android:color/transparent"
            android:text="Awais Ahmed"

            android:textColor="@color/black"
            android:textSize="23sp"

            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"/>
    </androidx.constraintlayout.widget.ConstraintLayout>
    </FrameLayout>

</androidx.cardview.widget.CardView>

离答案差得远呢! - undefined

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