CardView背景模糊和透明? Android Studio

huangapple go评论60阅读模式
英文:

CardView background blur and transparent? Android Studio

问题

<?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>

<details>
<summary>英文:</summary>

I&#39;m trying to make this:

[![enter image description here][1]][1]


and this is what I&#39;m getting:

[![enter image description here][2]][2]

I can&#39;t make the background blur and transparent at the same time, how could I do that?

when I try to do it with &quot;alpha&quot; it removes opacity in the text as well, which does not happen in the original photo.


    &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
    &lt;androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;match_parent&quot;
        xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
        xmlns:card_view=&quot;http://schemas.android.com/tools&quot;
        android:fitsSystemWindows=&quot;true&quot;&gt;
    
        &lt;androidx.cardview.widget.CardView
            android:layout_width=&quot;wrap_content&quot;
            android:layout_height=&quot;wrap_content&quot;
            app:cardCornerRadius=&quot;10dp&quot;
            android:layout_gravity=&quot;center|top&quot;
            android:layout_margin=&quot;8dp&quot;
            card_view:cardElevation=&quot;0dp&quot;&gt;
    
            &lt;androidx.cardview.widget.CardView
                android:layout_width=&quot;180dp&quot;
                android:layout_height=&quot;wrap_content&quot;
                app:cardCornerRadius=&quot;2dp&quot;
                android:layout_gravity=&quot;top&quot;
                android:layout_marginTop=&quot;130dp&quot;
                android:layout_marginStart=&quot;50dp&quot;
                card_view:cardBackgroundColor=&quot;@android:color/transparent&quot;
                card_view:cardElevation=&quot;10dp&quot;&gt;
    
                &lt;TextView
                    android:layout_width=&quot;wrap_content&quot;
                    android:layout_height=&quot;wrap_content&quot;
                    android:text=&quot;For example&quot;
                    android:layout_gravity=&quot;center&quot;
                    android:textColor=&quot;@color/colorAccent&quot;
                    android:textStyle=&quot;bold&quot; /&gt;
            &lt;/androidx.cardview.widget.CardView&gt;
            
    
            &lt;LinearLayout
                android:layout_width=&quot;280dp&quot;
                android:layout_height=&quot;180dp&quot;
                android:orientation=&quot;vertical&quot;&gt;
                
    
                &lt;ImageView
                    android:id=&quot;@+id/image&quot;
                    android:layout_width=&quot;match_parent&quot;
                    android:layout_height=&quot;180dp&quot;
                    android:src=&quot;@drawable/imagen1&quot;
                    android:scaleType=&quot;centerCrop&quot;/&gt;
                
            &lt;/LinearLayout&gt;
    
        &lt;/androidx.cardview.widget.CardView&gt;
        
    &lt;/androidx.coordinatorlayout.widget.CoordinatorLayout&gt;


  [1]: https://i.stack.imgur.com/s37q2.png
  [2]: https://i.stack.imgur.com/ZmK6V.png

</details>


# 答案1
**得分**: 1

```xml
<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>
英文:

You have use BlurKit Layout Inside Card View . Change Your Card View Content Like This .

   &lt;androidx.cardview.widget.CardView
    android:id=&quot;@+id/spdv_details_cv&quot;
    android:layout_width=&quot;0dp&quot;
    android:layout_height=&quot;0dp&quot;
    app:cardCornerRadius=&quot;20dp&quot;
    app:cardElevation=&quot;0dp&quot;

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

        app:blk_fps=&quot;1&quot; /&gt;
    &lt;androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;match_parent&quot; &gt;



        &lt;TextView
            android:layout_width=&quot;0dp&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:layout_margin=&quot;20dp&quot;
            android:background=&quot;@android:color/transparent&quot;
            android:text=&quot;Awais Ahmed&quot;

            android:textColor=&quot;@color/black&quot;
            android:textSize=&quot;23sp&quot;

            app:layout_constraintTop_toTopOf=&quot;parent&quot;
            app:layout_constraintStart_toStartOf=&quot;parent&quot;
            app:layout_constraintEnd_toEndOf=&quot;parent&quot;/&gt;
    &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
    &lt;/FrameLayout&gt;

&lt;/androidx.cardview.widget.CardView&gt;

huangapple
  • 本文由 发表于 2020年10月17日 08:21:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/64397925.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定