1

I am trying something that I didnt think would take hours. I want a cardview with a transparent background and slightly rounded corners. In the end it should look like this (the pink item at the top is some other view):

enter image description here

This is how far I have got:

enter image description here

Actually I thought I am done, and I just need to round the corners, and remove the stroke from the cardview. Well, it seems like these 2 things are not possible. When I set app:cardCornerRadius="8dp" this is the output I get:

enter image description here

Removing the stroke didn' work at all. In the end I created a rectangle shape inside drawable (where I set the stroke to 0dp), assigned it to the cardview and the stroke was gone, but I got a white background behind the rounded corners and I wasnt able to remove it.

This is my CardView Layout:

<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_margin="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:elevation="0dp"
app:cardCornerRadius="8dp"
app:cardPreventCornerOverlap="true"
app:cardBackgroundColor="#00123456"
> </CardView>

Is there a possibility to achive what I want (first pic)? Or should I let go of RecyclerView switch to ListView?

rimes
  • 761
  • 1
  • 8
  • 25
  • 1
    First of all why do u even need a `cardView` ? Just use a simple `view` set a `rounded rectangular transparent drawable background` thats it. If u need help will code it out for u – Santanu Sur Mar 10 '20 at 18:58
  • I think I was just working too much. I just had to remove cardview and i got what i wanted. Thank you! But changing the properties I asked, isn't possible for a card view, is it? (with an reasonable effort) – rimes Mar 10 '20 at 19:24

1 Answers1

0

Removing the CardView as the parent and putting a Constraintlayout, solved the problem.

<androidx.constraintlayout.widget.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/rounded_background"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
android:paddingTop="4dp"></ConstraintLayout>
rimes
  • 761
  • 1
  • 8
  • 25