RecyclerView with 3 by 3 item Horizontal scroll
up vote
0
down vote
favorite
In my project, I need to show the list of item in 3 by 3 on the horizontal scroll view with left and right arrow. If I click on the right arrow next 3 item should display like below image

I am confused that I need to go with ViewPager or RecyclerView with SnapHelper or PagerSnapHelper. Is there any other suggestions on how I can achieve it
add a comment |
up vote
0
down vote
favorite
In my project, I need to show the list of item in 3 by 3 on the horizontal scroll view with left and right arrow. If I click on the right arrow next 3 item should display like below image

I am confused that I need to go with ViewPager or RecyclerView with SnapHelper or PagerSnapHelper. Is there any other suggestions on how I can achieve it
Basically, you're asking for opinions on which component to use in this situation?
– Shark
Nov 20 at 18:04
Yes which is best option to use or any other components i can use for this situation
– Jagan
Nov 20 at 19:38
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
In my project, I need to show the list of item in 3 by 3 on the horizontal scroll view with left and right arrow. If I click on the right arrow next 3 item should display like below image

I am confused that I need to go with ViewPager or RecyclerView with SnapHelper or PagerSnapHelper. Is there any other suggestions on how I can achieve it
In my project, I need to show the list of item in 3 by 3 on the horizontal scroll view with left and right arrow. If I click on the right arrow next 3 item should display like below image

I am confused that I need to go with ViewPager or RecyclerView with SnapHelper or PagerSnapHelper. Is there any other suggestions on how I can achieve it
asked Nov 20 at 17:38
Jagan
1,5421432
1,5421432
Basically, you're asking for opinions on which component to use in this situation?
– Shark
Nov 20 at 18:04
Yes which is best option to use or any other components i can use for this situation
– Jagan
Nov 20 at 19:38
add a comment |
Basically, you're asking for opinions on which component to use in this situation?
– Shark
Nov 20 at 18:04
Yes which is best option to use or any other components i can use for this situation
– Jagan
Nov 20 at 19:38
Basically, you're asking for opinions on which component to use in this situation?
– Shark
Nov 20 at 18:04
Basically, you're asking for opinions on which component to use in this situation?
– Shark
Nov 20 at 18:04
Yes which is best option to use or any other components i can use for this situation
– Jagan
Nov 20 at 19:38
Yes which is best option to use or any other components i can use for this situation
– Jagan
Nov 20 at 19:38
add a comment |
1 Answer
1
active
oldest
votes
up vote
-1
down vote
For answer this qustion you should use viewpager and in any page use recycler and sending data 3 by 3 in page and set data to recycler.
The first Step you should add Viewpager in parent xml :
activity_main.xml
<ImageView
android:id="@+id/left_arrow"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignTop="@+id/view_pager"
android:rotation="180"
android:padding="8dp"
android:layout_alignBottom="@id/view_pager"
android:src="@drawable/ic_arrow"/>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:id="@+id/view_pager"
android:layout_toLeftOf="@id/right_arrow"
android:layout_toRightOf="@id/left_arrow"
android:layout_height="150dp"/>
<com.rd.PageIndicatorView
android:id="@+id/pageIndicatorView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/view_pager"
app:piv_animationType="worm"
app:piv_dynamicCount="true"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
app:piv_interactiveAnimation="true"
app:piv_radius="3dp"
app:piv_unselectedColor="#999999"
app:piv_selectedColor="#000000"
app:piv_viewPager="@id/view_pager"
attrs:piv_padding="8dp" />
<ImageView
android:id="@+id/right_arrow"
android:padding="8dp"
android:layout_alignTop="@+id/view_pager"
android:layout_alignBottom="@id/view_pager"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:src="@drawable/ic_arrow"/>
In this step you should create Viewpager adapter :
pageAdapter.kt
override fun getItem(position: Int): Fragment {
val firstItem = ((position + 1) * 3) - 2
val lastItem = ((position + 1) * 3)
val itemSet = arrayListOf<String>()
for (i in firstItem..lastItem) {
if (i <= items.size)
itemSet.add(items[i - 1])
}
return ItemFragment.newInstance(itemSet)
}
override fun getCount(): Int {
return size
}
In the third step, you should create a fragment to show each page of viewPager and just in Oncreate set recycler adapter and send data to adapter :
ItemFragment
// Creates the view controlled by the fragment
val view = inflater.inflate(R.layout.page, container, false)
val recycler = view.findViewById<RecyclerView>(R.id.recycler)
// Retrieve and display the movie data from the Bundle
val args = arguments
recycler.layoutManager = GridLayoutManager(activity,3)
recycler.adapter = ItemAdapter(args?.getStringArrayList("items")!!, this.activity!!)
And The Last Just create RecyclerAdapter and show data to each item in list:
ItemAdapter.kt
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(LayoutInflater.from(context).inflate(R.layout.item, parent, false))
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder?.title?.text = items.get(position)
}
override fun getItemCount(): Int {
return items.size
}
Result :

if you want to see the full source, just go to this link
1
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Comintern
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
-1
down vote
For answer this qustion you should use viewpager and in any page use recycler and sending data 3 by 3 in page and set data to recycler.
The first Step you should add Viewpager in parent xml :
activity_main.xml
<ImageView
android:id="@+id/left_arrow"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignTop="@+id/view_pager"
android:rotation="180"
android:padding="8dp"
android:layout_alignBottom="@id/view_pager"
android:src="@drawable/ic_arrow"/>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:id="@+id/view_pager"
android:layout_toLeftOf="@id/right_arrow"
android:layout_toRightOf="@id/left_arrow"
android:layout_height="150dp"/>
<com.rd.PageIndicatorView
android:id="@+id/pageIndicatorView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/view_pager"
app:piv_animationType="worm"
app:piv_dynamicCount="true"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
app:piv_interactiveAnimation="true"
app:piv_radius="3dp"
app:piv_unselectedColor="#999999"
app:piv_selectedColor="#000000"
app:piv_viewPager="@id/view_pager"
attrs:piv_padding="8dp" />
<ImageView
android:id="@+id/right_arrow"
android:padding="8dp"
android:layout_alignTop="@+id/view_pager"
android:layout_alignBottom="@id/view_pager"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:src="@drawable/ic_arrow"/>
In this step you should create Viewpager adapter :
pageAdapter.kt
override fun getItem(position: Int): Fragment {
val firstItem = ((position + 1) * 3) - 2
val lastItem = ((position + 1) * 3)
val itemSet = arrayListOf<String>()
for (i in firstItem..lastItem) {
if (i <= items.size)
itemSet.add(items[i - 1])
}
return ItemFragment.newInstance(itemSet)
}
override fun getCount(): Int {
return size
}
In the third step, you should create a fragment to show each page of viewPager and just in Oncreate set recycler adapter and send data to adapter :
ItemFragment
// Creates the view controlled by the fragment
val view = inflater.inflate(R.layout.page, container, false)
val recycler = view.findViewById<RecyclerView>(R.id.recycler)
// Retrieve and display the movie data from the Bundle
val args = arguments
recycler.layoutManager = GridLayoutManager(activity,3)
recycler.adapter = ItemAdapter(args?.getStringArrayList("items")!!, this.activity!!)
And The Last Just create RecyclerAdapter and show data to each item in list:
ItemAdapter.kt
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(LayoutInflater.from(context).inflate(R.layout.item, parent, false))
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder?.title?.text = items.get(position)
}
override fun getItemCount(): Int {
return items.size
}
Result :

if you want to see the full source, just go to this link
1
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Comintern
2 days ago
add a comment |
up vote
-1
down vote
For answer this qustion you should use viewpager and in any page use recycler and sending data 3 by 3 in page and set data to recycler.
The first Step you should add Viewpager in parent xml :
activity_main.xml
<ImageView
android:id="@+id/left_arrow"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignTop="@+id/view_pager"
android:rotation="180"
android:padding="8dp"
android:layout_alignBottom="@id/view_pager"
android:src="@drawable/ic_arrow"/>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:id="@+id/view_pager"
android:layout_toLeftOf="@id/right_arrow"
android:layout_toRightOf="@id/left_arrow"
android:layout_height="150dp"/>
<com.rd.PageIndicatorView
android:id="@+id/pageIndicatorView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/view_pager"
app:piv_animationType="worm"
app:piv_dynamicCount="true"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
app:piv_interactiveAnimation="true"
app:piv_radius="3dp"
app:piv_unselectedColor="#999999"
app:piv_selectedColor="#000000"
app:piv_viewPager="@id/view_pager"
attrs:piv_padding="8dp" />
<ImageView
android:id="@+id/right_arrow"
android:padding="8dp"
android:layout_alignTop="@+id/view_pager"
android:layout_alignBottom="@id/view_pager"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:src="@drawable/ic_arrow"/>
In this step you should create Viewpager adapter :
pageAdapter.kt
override fun getItem(position: Int): Fragment {
val firstItem = ((position + 1) * 3) - 2
val lastItem = ((position + 1) * 3)
val itemSet = arrayListOf<String>()
for (i in firstItem..lastItem) {
if (i <= items.size)
itemSet.add(items[i - 1])
}
return ItemFragment.newInstance(itemSet)
}
override fun getCount(): Int {
return size
}
In the third step, you should create a fragment to show each page of viewPager and just in Oncreate set recycler adapter and send data to adapter :
ItemFragment
// Creates the view controlled by the fragment
val view = inflater.inflate(R.layout.page, container, false)
val recycler = view.findViewById<RecyclerView>(R.id.recycler)
// Retrieve and display the movie data from the Bundle
val args = arguments
recycler.layoutManager = GridLayoutManager(activity,3)
recycler.adapter = ItemAdapter(args?.getStringArrayList("items")!!, this.activity!!)
And The Last Just create RecyclerAdapter and show data to each item in list:
ItemAdapter.kt
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(LayoutInflater.from(context).inflate(R.layout.item, parent, false))
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder?.title?.text = items.get(position)
}
override fun getItemCount(): Int {
return items.size
}
Result :

if you want to see the full source, just go to this link
1
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Comintern
2 days ago
add a comment |
up vote
-1
down vote
up vote
-1
down vote
For answer this qustion you should use viewpager and in any page use recycler and sending data 3 by 3 in page and set data to recycler.
The first Step you should add Viewpager in parent xml :
activity_main.xml
<ImageView
android:id="@+id/left_arrow"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignTop="@+id/view_pager"
android:rotation="180"
android:padding="8dp"
android:layout_alignBottom="@id/view_pager"
android:src="@drawable/ic_arrow"/>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:id="@+id/view_pager"
android:layout_toLeftOf="@id/right_arrow"
android:layout_toRightOf="@id/left_arrow"
android:layout_height="150dp"/>
<com.rd.PageIndicatorView
android:id="@+id/pageIndicatorView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/view_pager"
app:piv_animationType="worm"
app:piv_dynamicCount="true"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
app:piv_interactiveAnimation="true"
app:piv_radius="3dp"
app:piv_unselectedColor="#999999"
app:piv_selectedColor="#000000"
app:piv_viewPager="@id/view_pager"
attrs:piv_padding="8dp" />
<ImageView
android:id="@+id/right_arrow"
android:padding="8dp"
android:layout_alignTop="@+id/view_pager"
android:layout_alignBottom="@id/view_pager"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:src="@drawable/ic_arrow"/>
In this step you should create Viewpager adapter :
pageAdapter.kt
override fun getItem(position: Int): Fragment {
val firstItem = ((position + 1) * 3) - 2
val lastItem = ((position + 1) * 3)
val itemSet = arrayListOf<String>()
for (i in firstItem..lastItem) {
if (i <= items.size)
itemSet.add(items[i - 1])
}
return ItemFragment.newInstance(itemSet)
}
override fun getCount(): Int {
return size
}
In the third step, you should create a fragment to show each page of viewPager and just in Oncreate set recycler adapter and send data to adapter :
ItemFragment
// Creates the view controlled by the fragment
val view = inflater.inflate(R.layout.page, container, false)
val recycler = view.findViewById<RecyclerView>(R.id.recycler)
// Retrieve and display the movie data from the Bundle
val args = arguments
recycler.layoutManager = GridLayoutManager(activity,3)
recycler.adapter = ItemAdapter(args?.getStringArrayList("items")!!, this.activity!!)
And The Last Just create RecyclerAdapter and show data to each item in list:
ItemAdapter.kt
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(LayoutInflater.from(context).inflate(R.layout.item, parent, false))
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder?.title?.text = items.get(position)
}
override fun getItemCount(): Int {
return items.size
}
Result :

if you want to see the full source, just go to this link
For answer this qustion you should use viewpager and in any page use recycler and sending data 3 by 3 in page and set data to recycler.
The first Step you should add Viewpager in parent xml :
activity_main.xml
<ImageView
android:id="@+id/left_arrow"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignTop="@+id/view_pager"
android:rotation="180"
android:padding="8dp"
android:layout_alignBottom="@id/view_pager"
android:src="@drawable/ic_arrow"/>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:id="@+id/view_pager"
android:layout_toLeftOf="@id/right_arrow"
android:layout_toRightOf="@id/left_arrow"
android:layout_height="150dp"/>
<com.rd.PageIndicatorView
android:id="@+id/pageIndicatorView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/view_pager"
app:piv_animationType="worm"
app:piv_dynamicCount="true"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
app:piv_interactiveAnimation="true"
app:piv_radius="3dp"
app:piv_unselectedColor="#999999"
app:piv_selectedColor="#000000"
app:piv_viewPager="@id/view_pager"
attrs:piv_padding="8dp" />
<ImageView
android:id="@+id/right_arrow"
android:padding="8dp"
android:layout_alignTop="@+id/view_pager"
android:layout_alignBottom="@id/view_pager"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:src="@drawable/ic_arrow"/>
In this step you should create Viewpager adapter :
pageAdapter.kt
override fun getItem(position: Int): Fragment {
val firstItem = ((position + 1) * 3) - 2
val lastItem = ((position + 1) * 3)
val itemSet = arrayListOf<String>()
for (i in firstItem..lastItem) {
if (i <= items.size)
itemSet.add(items[i - 1])
}
return ItemFragment.newInstance(itemSet)
}
override fun getCount(): Int {
return size
}
In the third step, you should create a fragment to show each page of viewPager and just in Oncreate set recycler adapter and send data to adapter :
ItemFragment
// Creates the view controlled by the fragment
val view = inflater.inflate(R.layout.page, container, false)
val recycler = view.findViewById<RecyclerView>(R.id.recycler)
// Retrieve and display the movie data from the Bundle
val args = arguments
recycler.layoutManager = GridLayoutManager(activity,3)
recycler.adapter = ItemAdapter(args?.getStringArrayList("items")!!, this.activity!!)
And The Last Just create RecyclerAdapter and show data to each item in list:
ItemAdapter.kt
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(LayoutInflater.from(context).inflate(R.layout.item, parent, false))
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder?.title?.text = items.get(position)
}
override fun getItemCount(): Int {
return items.size
}
Result :

if you want to see the full source, just go to this link
edited 2 days ago
answered Nov 20 at 23:35
Hassan Naghibi
295
295
1
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Comintern
2 days ago
add a comment |
1
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Comintern
2 days ago
1
1
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Comintern
2 days ago
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Comintern
2 days ago
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398561%2frecyclerview-with-3-by-3-item-horizontal-scroll%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Basically, you're asking for opinions on which component to use in this situation?
– Shark
Nov 20 at 18:04
Yes which is best option to use or any other components i can use for this situation
– Jagan
Nov 20 at 19:38