I'm inflating a custom layout with CardView inside the layout. The rounded corners are displayed as expected but I also get grey background behind the corners.
The code is simple, uses a CardView with corner radius and a background color. I've tried setting transparent background but doesn't work. However, if i set another opaque color, it is displayed in corners.
Code is attached.
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/transparent"> <android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="wrap_content" app:cardBackgroundColor="@android:color/white" app:cardCornerRadius="6dp" app:cardElevation="5dp"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent"> <TextView android:id="@+id/tvProgress" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_centerVertical="true" android:layout_toLeftOf="@+id/ivIcon" android:layout_toStartOf="@+id/ivIcon" android:background="@android:color/transparent" android:padding="@dimen/elementPaddingSmall" android:text="Initial Discussion" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="@android:color/black" /> <ImageView android:id="@+id/ivIcon" android:layout_width="50dp" android:layout_height="50dp" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:background="@color/lightBrown" android:scaleType="centerInside" android:src="@drawable/ic_checkmark_circle" /> </RelativeLayout> </android.support.v7.widget.CardView> </RelativeLayout>
Result:
Create a layout and set its background to your shape drawable. Wrap that layout around your ImageView (with no padding) The ImageView (including anything else in the layout) will now display with rounded layout shape.
CardView is a new widget in Android that can be used to display any sort of data by providing a rounded corner layout along with a specific elevation. CardView is the view that can display views on top of each other.
class CardElevation. Represents the elevation for a card in different states. See CardDefaults. cardElevation for the default elevation used in a Card .
It is because of shadow, you need to give space to cardview to show full shadow. Add android:layout_margin="5dp"
to CardView and you will see that the "grey" color is cut shadow.
Solution is adding app:cardUseCompatPadding="true"
to CardView and it will give needed spacing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With