android - Center each child view in RecyclerView -


i'm trying create horizontal recyclerview consists of cards. want each card displayed in center of screen , can scroll horizontally. set linearlayoutmanagerto horizontal :

linearlayoutmanager = new linearlayoutmanager(getactivity(),              linearlayoutmanager.horizontal, false); recyclerview.setlayoutmanager(linearlayoutmanager); 

the xml fragment follows :

<framelayout     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:layout_gravity="center"     tools:context="com.rubberduck.pairup.fragments.favoritesfragment">      <android.support.v7.widget.recyclerview         android:id="@+id/rv_favorites"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:padding="1dp"         android:layout_gravity="center"         android:scrollbars="vertical" /> </framelayout> 

i've set layout_gravity center in cardview child view recyclerview no avail. card displayed on top left.

how can accomplish this?

edit

cardview :

<?xml version="1.0" encoding="utf-8"?> <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:id="@+id/cv_pair"     cardusecompatpadding="true"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_centerinparent="true"     card_view:cardcornerradius="4dp">      <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"         android:layout_width="wrap_content"         android:layout_height="wrap_content">      <imageview         android:id="@+id/iv_shirt"         android:layout_width="@dimen/image_width"         android:layout_height="@dimen/image_height"         android:scaletype="centercrop"         android:src="@drawable/tshirt" />      <imageview         android:id="@+id/iv_trouser"         android:layout_width="@dimen/image_width"         android:layout_height="@dimen/image_height"         android:layout_torightof="@id/iv_shirt"         android:scaletype="centercrop"         android:src="@drawable/jeans" />      </relativelayout>  </android.support.v7.widget.cardview> 


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -