RecyclerView with 3 by 3 item Horizontal scroll
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 |
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 '18 at 18:04
Yes which is best option to use or any other components i can use for this situation
– Jagan
Nov 20 '18 at 19:38
add a comment |
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 '18 at 17:38
JaganJagan
4721130
4721130
Basically, you're asking for opinions on which component to use in this situation?
– Shark
Nov 20 '18 at 18:04
Yes which is best option to use or any other components i can use for this situation
– Jagan
Nov 20 '18 at 19:38
add a comment |
Basically, you're asking for opinions on which component to use in this situation?
– Shark
Nov 20 '18 at 18:04
Yes which is best option to use or any other components i can use for this situation
– Jagan
Nov 20 '18 at 19:38
Basically, you're asking for opinions on which component to use in this situation?
– Shark
Nov 20 '18 at 18:04
Basically, you're asking for opinions on which component to use in this situation?
– Shark
Nov 20 '18 at 18:04
Yes which is best option to use or any other components i can use for this situation
– Jagan
Nov 20 '18 at 19:38
Yes which is best option to use or any other components i can use for this situation
– Jagan
Nov 20 '18 at 19:38
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
add a comment |
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
add a comment |
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 Nov 21 '18 at 8:44
answered Nov 20 '18 at 23:35
Hassan NaghibiHassan Naghibi
395
395
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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 '18 at 18:04
Yes which is best option to use or any other components i can use for this situation
– Jagan
Nov 20 '18 at 19:38