I am using recycler view to to populate the data on the screen. I am using List Adapter instead of using Recycler View Adapter and Below's code as a ListItem3
Layout.
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent">
<com.google.android.material.card.MaterialCardView
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
app:cardCornerRadius="8dp"
app:cardElevation="4dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/social_media_icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="8dp"
android:padding="6dp"
android:scaleType="fitStart"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/social_media_icon_name"
style="@style/TextAppearance.AppCompat.Headline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
app:layout_constraintBottom_toBottomOf="@id/social_media_icon"
app:layout_constraintStart_toEndOf="@id/social_media_icon"
app:layout_constraintTop_toTopOf="@id/social_media_icon"
tools:text="Icon Name" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
Here the width of the card view is match_parent, also in a preview of the layout it's width is match_parent, but while running the app it is visible as wrap_content instead of match_parent.
Also I have used the same layout code for another Fragment using Recycler View Adapter instead of ListAdapter, there the layout_width attribute is working perfectly fine.
So Please help me to find the Error.