-2

Fragment set recyclerView columns number:

sortRecyclerView.setHasFixedSize(true);
        RecyclerView.LayoutManager rvLayoutManager = new GridLayoutManager(getActivity(), 2);
        sortRecyclerView.setLayoutManager(rvLayoutManager);

Here layout that content recyclerView:

<?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="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/sortRecyclerView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:scrollbars="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

Here item layout in recyclerView:

<?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_marginTop="20dp"
    android:background="@color/place_holder_color">

    <ImageView
        android:id="@+id/imageViewPhoto"
        android:layout_width="@dimen/preview_image_height"
        android:layout_height="@dimen/preview_image_height"
        android:scaleType="centerCrop"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />



</android.support.constraint.ConstraintLayout>

And here result:

rv

I need next:

  1. Set 20dp on the left and right side
  2. set 10 dp between 2 columns
Alex
  • 633
  • 1
  • 7
  • 18

2 Answers2

0

You can set something like this: - for the 1'st ImageView:

android:paddingLeft="10dp"
android:paddingRight="5dp"
  • for the 2'nd ImageView:

    android:paddingLeft="5dp"

    android:paddingRight="10dp"

jorjSB
  • 610
  • 4
  • 12
0

add to the one on the left:

android:marginRight="5dp"

android:marginLeft="20dp"

add to the one on the right:

android:marginLeft="5dp"

android:marginRight="20dp"

Thorvald
  • 3,424
  • 6
  • 40
  • 66
  • No two images. I have recyclerView with 2 columns. On every column show only ONE ImageView "@+id/imageViewPhoto" – Alex Nov 24 '17 at 16:16
  • add that code to the parent layout and I suggest you work with `Relative layout` – Thorvald Nov 24 '17 at 16:27
  • I found solution. I must extends RecyclerView.ItemDecoration and override method getItemOffsets() – Alex Nov 24 '17 at 17:03