Android recyclerView with cardview layout issue

cardview'' android dependency
cardview android example code
cardview android material design example
android cardview with image and text example
simple recyclerview and cardview android example
android-cardview androidx
add cardview to recyclerview
how to design cardview in android

I am creating a layout as show in the First image. I am using RecyclerView with Cardview to complete this screen but as you can see in the emulator output i am not getting the desired layout(shown in the first Image) as it looks crazy as all items should be aligned respectively just like HTML Table in the WEB and should work same on all devices.

Here is my Layout Resource XML file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/textViewStatus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:text="TextView" />

    <TextView
        android:id="@+id/textViewHomeTeam"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="false"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/textViewStatus"
        android:text="TextView" />

    <ImageView
        android:id="@+id/imageViewHomeTeamLogo"
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:layout_centerInParent="false"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/textViewHomeTeam"
        android:padding="4dp" />

    <TextView
        android:id="@+id/textViewScore"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="false"
        android:layout_toRightOf="@+id/imageViewHomeTeamLogo"
        android:text="TextView" />

    <TextView
        android:id="@+id/textViewMatchStatus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textViewStatus"
        android:layout_centerInParent="false"
        android:layout_toEndOf="@+id/imageViewHomeTeamLogo"
        android:text="TextView" />

    <ImageView
        android:id="@+id/imageViewAwayTeamLogo"
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:layout_centerInParent="false"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/textViewScore"
        android:padding="4dp" />

    <TextView
        android:id="@+id/textViewAwayTeam"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="false"
        android:layout_centerHorizontal="false"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/imageViewAwayTeamLogo"
        android:text="TextView" />

    </RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>

Please correct me what is missing.


Replace your onCreateViewHolder with following one

@Override
    public CountryListAdapter onCreateViewHolder(ViewGroup parent, int viewType) {
        View view;
        view = LayoutInflater.from(mContext).inflate(R.layout."your_layout", null);

        RecyclerView.LayoutParams params = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(params);

        CountryListAdapter viewHolder = new CountryListAdapter(view);
        return viewHolder;
    }

Layout issue of RecyclerView and CardView, Firstly, create your RecyclerView code for your layout. <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="  Dependency for Recyclerview with card view. Most importantly, The RecyclerView is available in the support library. So we need to add one script in Gradle dependency. compile 'com.android.support:recyclerview-v7:23.0.1' After that, to use the CardView in your app, add the CardView dependency in Gradle. compile 'com.android.support:cardview-v7:23.0.1'


You can use Linear layout with horizontal orientation inside card view.

<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent">

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

</RelativeLayout>

Recyclerview with card view android example, Its a FrameLayout with shadow, corner radius and elevation property after Android Lollipop. CardView is mostly used for good looking UI with RecyclerView​. Here  Freshbyte labs is aimed at providing android tutorials centered around json parsing. You could also expect tutorials on web hosting as well FreshByte Labs: Android Recyclerview with Cardview example : json parsing using retrofit


Hey I am giving you rough layout might help you,

 <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp" >

    <TextView
        android:id="@+id/textViewStatus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="FT"
        android:padding="8dp"
        android:background="@drawable/text_drawable"
        android:textSize="16sp"/>

    <TextView
        android:id="@+id/textViewHomeTeam"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="35dp"
        android:layout_marginLeft="35dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toRightOf="@+id/textViewStatus"
        android:text="Arsenol" />

    <ImageView
        android:id="@+id/imageViewHomeTeamLogo"
        android:layout_width="25dp"
        android:layout_height="match_parent"
        android:layout_marginLeft="10dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toRightOf="@+id/textViewHomeTeam"
        android:padding="4dp" />

    <TextView
        android:id="@+id/textViewScore"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintLeft_toRightOf="@+id/imageViewHomeTeamLogo"
        android:text="21:00"
        android:textStyle="bold"/>

    <TextView
        android:id="@+id/textViewMatchStatus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/textViewStatus"
        app:layout_constraintLeft_toRightOf="@+id/imageViewHomeTeamLogo"
        android:text="Not Started" />

    <ImageView
        android:id="@+id/imageViewAwayTeamLogo"
        android:layout_width="25dp"
        android:layout_marginLeft="12dp"
        android:layout_height="match_parent"
        android:src="@color/colorAccent"
        app:layout_constraintLeft_toRightOf="@+id/textViewMatchStatus"
        android:padding="4dp" />

    <TextView
        android:id="@+id/textViewAwayTeam"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toRightOf="@+id/imageViewAwayTeamLogo"
        android:text="Leisure city" />

Android CardView with RecyclerView - Droid By Me, It is all because of dependency and android version problems. If you are Replace the specifications for RecyclerView and CardView in your layouts. If you see  Android RecyclerView is similar to ListView except that it forces us to use RecyclerView.ViewHolder class to hold the elements which is not a compulsion in ListView. As the name suggests, Android RecyclerView is used to reuse cells when scrolling up and down by recycling the items in the list.


update your layout with below layout:

<?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="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:weightSum="4">

            <ImageView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5" />

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="horizontal"
                android:gravity="end">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="0.3" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:layout_weight="1"
                android:gravity="center">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

            </LinearLayout>


            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="horizontal">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"/>

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1" />

            </LinearLayout>

            <ImageView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5" />

        </LinearLayout>
    </android.support.v7.widget.CardView>
</LinearLayout>

RecyclerView & CardView not working properly in 2020?, CardView uses real elevation and dynamic shadows on Android 5.0 (API level 21​) and above and falls back to a programmatic shadow  RecyclerView and CardView got introduced in android Lollipop. Basically The RecyclerView widget is a more advanced and flexible version of ListView. When we need to display a scrolling list of


Create a Card-Based Layout, In this RecyclerView Android Example, We will create a custom layout with CardView and render it on RecyclerView. We discuss in detail about some relevant  The overall container for your user interface is a RecyclerView object that you add to your layout. The RecyclerView fills itself with views provided by a layout manager that you provide. You can use one of our standard layout managers (such as LinearLayoutManager or GridLayoutManager), or implement your own.


RecyclerView in Android Example Best Practices, Android RecyclerView example, android recycler view multiple view types example In this tutorial, we'll implement heterogeneous layouts inside a RecyclerView. CardView xmlns:card_view="https://schemas.android.com/apk/​res-auto" the issue is that i can update the first 4 rows very well, but after that it crashes. and  The new support library in Android L introduced two new UI widgets: RecyclerView and CardView. The RecyclerView is a more advanced and more flexible version of the ListView. This new component is a big step because the ListView is one of the most used UI widgets. The CardView widget, on the other hand, is a new component that does not


Android RecyclerView Example - Multiple ViewTypes, Working with the RecyclerView and CardView Widgets, An Android Layout Editor Android Studio 3.6 Development Essentials - Java Edition Print and eBook  Using CardView you can represent the information in a card manner with a drop shadow (elevation) and corner radius which looks consistent across the platform. CardView extends the FrameLayout and it is supported way back to Android 2.x. You can achieve good looking UI when CardView is combined with RecyclerView.