I display in the CardView list of CardView repositories that the search returns to me, but here I have a little problem — CardView does not stretch across the width of the screen. With markup, everything seems to be fine:

enter image description here

Activity markup

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_repo" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="@color/github" android:orientation="vertical"> <ImageView android:id="@+id/github_ava" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_gravity="center" android:layout_weight="8" /> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="horizontal"> <TextView android:id="@+id/github_name" android:layout_width="0dp" android:layout_weight="7" android:textSize="18sp" android:layout_height="wrap_content" android:layout_gravity="left" /> <ImageView android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:layout_gravity="right" android:id="@+id/search_repo" android:src="@drawable/ic_magnify" /> </LinearLayout> </LinearLayout> <android.support.v7.widget.RecyclerView android:id="@+id/recycler_conteiner" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="2" /> </LinearLayout> 

Cardview

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" card_view:cardCornerRadius="12dp" card_view:cardElevation="5dp" card_view:cardUseCompatPadding="true" android:layout_gravity="center"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/repo_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="3dp" android:layout_marginLeft="5dp" android:text="repo_name" android:textSize="20sp" /> <TextView android:id="@+id/repo_description" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:text="repo_description" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:id="@+id/repo_language" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginRight="10dp" android:text="repo_language" /> <TextView android:id="@+id/repo_last_update" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginRight="5dp" android:text="repo_last_update" /> </LinearLayout> </LinearLayout> </android.support.v7.widget.CardView> </LinearLayout> 

    1 answer 1

    In your adapter, in the onCreateViewHolder method onCreateViewHolder how does markup inflate occur? It should be so

     LayoutInflater.from(parent.getContext()) .inflate(R.layout.card_listitem, parent, false); 
    • Yes, now the card has stretched to the full width, but it has also grown in height (on the whole screen one card is obtained - drugs_and_code
    • This is because your CardView is in LinearLayout , whose height is set to match_parent - Flippy