I have a problem adjusting the width of a cardview. I have all widths set to "match_parent" but the list of cardviews is displayed like this:[screenshot]
The cardviews are the items of a recyclerview, this is the recyclerview layout code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/toolbar"/>
<Button
android:id="@+id/escanearCodigo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Escanear codigo"
android:layout_weight="1"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
And this is the code of the items formed by cardviews:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_margin="12dp"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="#81C784"
app:cardCornerRadius="9dp"
app:cardElevation="3dp"
app:contentPadding="10dp"
android:layout_margin="5dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/idCodigo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/idNombre"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>