1

i am trying to make CardView with elevation but the issue is when i use no-alpha color like "#ffffff" it works fine but when i set some alpha color like #b0ffffffit shows another inner view with elevation like this

enter image description here

but when i set non-alpha color like"#ffffff" it works fine

enter image description here

and this is my layout

    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:background="#b0ffffff"
    android:layout_centerInParent="true"
    card_view:cardBackgroundColor="#b0ffffff"
    card_view:cardElevation="5dp">

    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:src="@drawable/people" />

</android.support.v7.widget.CardView>

btw i am trying to make a view like this

enter image description here

Phantômaxx
  • 37,352
  • 21
  • 80
  • 110
Mateen Chaudhry
  • 604
  • 12
  • 27

3 Answers3

0

just remove the line:

card_view:cardBackgroundColor="#b0ffffff"

and it should work

Udit
  • 1,017
  • 6
  • 11
0

Try this

           <android.support.v7.widget.CardView
                android:layout_width="100dp"
                android:layout_height="100dp"
                app:cardBackgroundColor="#B0FFFFFF"
                app:cardCornerRadius="50dp"
                app:cardElevation="5dp">

                <ImageView
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:layout_gravity="center"
                    android:src="@drawable/people" />

            </android.support.v7.widget.CardView>
0

If you are seeing annoying border around your CardView, you can try the code below, as mentioned in 배준모's answer. This also should work with androidx.cardview.widget.CardView.

<android.support.v7.widget.CardView
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_margin="@dimen/margin"
    android:background="@android:color/transparent"
    android:elevation="0dp"
    app:cardBackgroundColor="@color/form_card_bg_color"
    app:cardElevation="0dp"
    app:contentPadding="@dimen/margin_large"
    app:cardPreventCornerOverlap="false"
    app:cardUseCompatPadding="true" >
Firzen
  • 1,797
  • 9
  • 27
  • 41