Here is how I construct the recycle view
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
ItemData itemsData[] = { new ItemData("Help",R.drawable.profile_pic),
new ItemData("Delete",R.drawable.profile_pic),
new ItemData("Cloud",R.drawable.profile_pic),
new ItemData("Favorite",R.drawable.profile_pic),
new ItemData("Like",R.drawable.profile_pic),
new ItemData("Rating",R.drawable.profile_pic)};
LinearLayoutManager l = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(l);
MyAdapter mAdapter = new MyAdapter(itemsData);
recyclerView.setAdapter(mAdapter);
recyclerView.setItemAnimator(new DefaultItemAnimator());
It works but the problem is it show only 1 item per time, how to change to 2 item? that means , the icon should be 50% of the screen width and total have 2 icons per page
Like this (no need of divider):
icon1 | icon2
XML (Main Activity)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="match_parent"
tools:context="com.hmkcode.android.recyclerview.MainActivity" >
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
/>
</RelativeLayout>
XML (item)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="80dp">
<!-- icon -->
<ImageView
android:id="@+id/item_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/profile_pic" />
<!-- title -->
<TextView
android:id="@+id/item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="#000000"
android:textSize="22sp" />
</RelativeLayout>
Thanks for helping
Update :
Notice The app only have potarit orientation so can ignore the case for landscape
Current result:
What I would like to achieve similar to
And GridLayoutManager is not the exact behavior
GridLayoutManager g = new GridLayoutManager(this, 2, GridLayoutManager.HORIZONTAL, false);