CardView top left and right rounded corners not showing.

Florence Njeri
1 min readMar 18, 2020

--

I have recently encountered a bug where I was setting the card radius to 25 dp yet it was not rounding the top corners of the CadView but only showed the rounded corners for the bottom of the CardView.

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="25dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/ingredients_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:itemCount="6" app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/recipe_item" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/explore_more_ingredients"
android:textColor="@color/backgroundGreen"
android:gravity="center_horizontal"
android:textSize="16sp"
android:layout_marginTop="16dp"
android:paddingBottom="16dp"
android:background="@color/white"
/>
</LinearLayout>

</androidx.cardview.widget.CardView>

Here is a screenshot of the buggy UI:

The buggy UI

Solution

I solved it by adding a margin-top of 16dp to the RecyclerView. Turns out that the RecyclerView was overlapping with the rounded corners.

Bug fixed.

I flattened the bottom corners by simply setting the text width to match_parent then set the TextView background to white

Hope this helps. happy coding!!

--

--

Florence Njeri
Florence Njeri

Written by Florence Njeri

Software Engineering || Career || Life

No responses yet