-1

I am making recyclerView with cardview which is working fine.but this is working for android devices and this recyclerView is not responsive to a tablet size. How i can make the responsive layout of recyclerview which will show same products as shown as in mobile and tablet? how i can do that? here is my recyclerView xml Code:

<?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" >
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/tvTopBrands"
    android:text="@string/top_brand"
    android:textAlignment="center"
    android:layout_marginTop="5dp"
    android:textColor="@color/colorPrimary"
    android:textSize="20sp"
    android:textStyle="bold|italic"/>

<android.support.v7.widget.RecyclerView
    android:id="@+id/rvTopBrandProducts"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="4dp"
    android:layout_marginStart="4dp"
    android:layout_marginTop="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/tvTopBrands"
    app:layout_constraintVertical_bias="0.0" />
</LinearLayout>

and here is my recyclerView code:

final JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET,
            URLs.viewAllLatestProduct,null,
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {
                    setLatestProductAdapter(response);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
        }
    });

and here is my cardView layout:

<android.support.v7.widget.CardView android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="2dp"
    android:background="@android:color/holo_orange_dark">

    <ImageView
        android:id="@+id/ivTopBrand"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:padding="2dp"
        android:background="@color/white"
        android:layout_centerHorizontal="true"
        android:src="@drawable/ic_feature_brand" />
</LinearLayout>

how i can make responsive layout

Anser Abbas
  • 59
  • 3
  • 11

2 Answers2

0

hey dear you just have to use RecyclerView with dummy item. you must focus on the layout that every time you are going to use to display item in RecyclerView. if you make a reponsive layout for that item your whole RecyclerView will be rrsponsive.

0

In your code you used dp which is differ device to device. So your layout will not adjust as per your requirement. To solve it you can try this android library and redefine all your xml dp value with that lib dp value.

Mahesh
  • 42
  • 2