question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RecyclerView CardView Bug

See original GitHub issue

I’m using the Kotlin Builder (ViewBinding) way to init the recyclerView, When trying to bind my layout with a cardView, it won’t respect the match_parent width, its always wrap content The strange thing is, it worked with a normal RecyclerView, pretty sure it’s a problem from the lib, please take a look

here is the layout of the single Item

<?xml version="1.0" encoding="utf-8"?>

<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:cardView="http://schemas.android.com/apk/res-auto"
    android:id="@+id/cardView"
    android:layout_width="match_parent"
    android:layout_height="90dp"
    cardView:cardPreventCornerOverlap="true"
    cardView:cardCornerRadius="8dp"
    cardView:cardElevation="8dp"
    android:layout_margin="8dp">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/image_restaurant"
            android:layout_width="130dp"
            android:layout_height="0dp"
            android:scaleType="centerInside"
            cardView:layout_constraintBottom_toBottomOf="parent"
            cardView:layout_constraintStart_toStartOf="parent"
            cardView:layout_constraintTop_toTopOf="parent"
            tools:background="@tools:sample/backgrounds/scenic"
            tools:ignore="ContentDescription" />

        <TextView
            android:id="@+id/restaurant_name"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="8dp"
            android:fontFamily="sans-serif-smallcaps"
            android:gravity="center"
            android:lines="1"
            android:padding="5dp"
            android:textAppearance="@style/TextAppearance.AppCompat.Title"
            android:textColor="@android:color/black"
            android:textStyle="bold"
            cardView:layout_constraintStart_toEndOf="@id/image_restaurant"
            cardView:layout_constraintEnd_toEndOf="parent"
            cardView:layout_constraintTop_toTopOf="parent"
            tools:text="@tools:sample/full_names" />

        <TextView
            android:id="@+id/openingHours"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Dimanche  - jeudi  21h30 jeudi  21h30  jeudi  21h30  jeudi  21h30  jeudi  21h30   22-40"
            android:textStyle="bold"
            cardView:layout_constraintBottom_toBottomOf="parent"
            cardView:layout_constraintEnd_toEndOf="parent"
            cardView:layout_constraintStart_toEndOf="@+id/image_restaurant"
            cardView:layout_constraintTop_toBottomOf="@+id/restaurant_name" />


    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
amirisbackcommented, Jan 29, 2022
Screen Shot 2022-01-29 at 22 57 21

I’ve tried it, everything works fine, you can try my sample code

Read more comments on GitHub >

github_iconTop Results From Across the Web

CardView is not showing properly in RecyclerView
I have compiled card view library in gradle file but the problem is card view is not showing there is no elevation and...
Read more >
Android avoid weird cardview and recyclerview bugs caused ...
Android avoid weird cardview and recyclerview bugs caused by different support library dependencies. - build.gradle.
Read more >
v7 cardview library issues [37007602] - Visible to Public
https://github.com/bignerdranch/recyclerview-multiselect. This error occurs every time on 4.4.4, but not on 5.0 and occurs at times on 4.1.2 ...
Read more >
CardView using RecyclerView in Android with Example
RecyclerView works on the ViewHolder design pattern so we have to create a Data class that holds data for RecyclerView and a ViewHolder...
Read more >
Android RecyclerView, Android CardView Example Tutorial
Android CardView widget allows us to control the background color, shadow, corner radius, elevation etc. For using the custom attributes in XML, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found