How to set horizontal scroll with show next and previous data in RecyclerView









up vote
0
down vote

favorite












In my application i want use recyclerView for show special data, and for this i want use recyclerview with horizontal scroll with show next and previous data.

such as banner and below image : enter link description here



How can i use LayoutManager for this?



For this, i know i should use Horizontal in LinearLayout. but i don't know how can i show next and previous data



Please don't give me negative points and please help me.










share|improve this question























  • Why you can not try ViewPager
    – Sniffer
    Nov 11 at 5:59










  • @Sniffer, i want use RecyclerView. can you help me for this?
    – DJ Al
    Nov 11 at 6:01










  • next/previous arrow indicator please follow this link it work for me.
    – dhananjay singh
    Nov 11 at 6:13










  • @dhananjaysingh, thanks dear but i don't want show next and previous arrow . i want partial next and previous data
    – DJ Al
    Nov 11 at 6:20














up vote
0
down vote

favorite












In my application i want use recyclerView for show special data, and for this i want use recyclerview with horizontal scroll with show next and previous data.

such as banner and below image : enter link description here



How can i use LayoutManager for this?



For this, i know i should use Horizontal in LinearLayout. but i don't know how can i show next and previous data



Please don't give me negative points and please help me.










share|improve this question























  • Why you can not try ViewPager
    – Sniffer
    Nov 11 at 5:59










  • @Sniffer, i want use RecyclerView. can you help me for this?
    – DJ Al
    Nov 11 at 6:01










  • next/previous arrow indicator please follow this link it work for me.
    – dhananjay singh
    Nov 11 at 6:13










  • @dhananjaysingh, thanks dear but i don't want show next and previous arrow . i want partial next and previous data
    – DJ Al
    Nov 11 at 6:20












up vote
0
down vote

favorite









up vote
0
down vote

favorite











In my application i want use recyclerView for show special data, and for this i want use recyclerview with horizontal scroll with show next and previous data.

such as banner and below image : enter link description here



How can i use LayoutManager for this?



For this, i know i should use Horizontal in LinearLayout. but i don't know how can i show next and previous data



Please don't give me negative points and please help me.










share|improve this question















In my application i want use recyclerView for show special data, and for this i want use recyclerview with horizontal scroll with show next and previous data.

such as banner and below image : enter link description here



How can i use LayoutManager for this?



For this, i know i should use Horizontal in LinearLayout. but i don't know how can i show next and previous data



Please don't give me negative points and please help me.







android android-layout android-recyclerview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 at 1:14









Andrew Thompson

152k27162336




152k27162336










asked Nov 11 at 5:42









DJ Al

116




116











  • Why you can not try ViewPager
    – Sniffer
    Nov 11 at 5:59










  • @Sniffer, i want use RecyclerView. can you help me for this?
    – DJ Al
    Nov 11 at 6:01










  • next/previous arrow indicator please follow this link it work for me.
    – dhananjay singh
    Nov 11 at 6:13










  • @dhananjaysingh, thanks dear but i don't want show next and previous arrow . i want partial next and previous data
    – DJ Al
    Nov 11 at 6:20
















  • Why you can not try ViewPager
    – Sniffer
    Nov 11 at 5:59










  • @Sniffer, i want use RecyclerView. can you help me for this?
    – DJ Al
    Nov 11 at 6:01










  • next/previous arrow indicator please follow this link it work for me.
    – dhananjay singh
    Nov 11 at 6:13










  • @dhananjaysingh, thanks dear but i don't want show next and previous arrow . i want partial next and previous data
    – DJ Al
    Nov 11 at 6:20















Why you can not try ViewPager
– Sniffer
Nov 11 at 5:59




Why you can not try ViewPager
– Sniffer
Nov 11 at 5:59












@Sniffer, i want use RecyclerView. can you help me for this?
– DJ Al
Nov 11 at 6:01




@Sniffer, i want use RecyclerView. can you help me for this?
– DJ Al
Nov 11 at 6:01












next/previous arrow indicator please follow this link it work for me.
– dhananjay singh
Nov 11 at 6:13




next/previous arrow indicator please follow this link it work for me.
– dhananjay singh
Nov 11 at 6:13












@dhananjaysingh, thanks dear but i don't want show next and previous arrow . i want partial next and previous data
– DJ Al
Nov 11 at 6:20




@dhananjaysingh, thanks dear but i don't want show next and previous arrow . i want partial next and previous data
– DJ Al
Nov 11 at 6:20












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










Assuming you need to only show one full item at a time and 2 partial items at both the sides. You can use snaphelper to snap recylerview to nearest item position for having the desired effect. And change the width of your item inside the recycler view in the following way. You need to pass the recyclerView reference inside your adapter to get the width.



@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
final SnapHelper snapHelper = new PagerSnapHelper();
snapHelper.attachToRecyclerView(recyclerView);



and in your onCreateViewHolder change the width of your item.



public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int i) 
final View view =
LayoutInflater.from(parent.getContext())
.inflate(R.layout.your_view, parent, false);
// recyclerView is your passed view.
int width = recyclerView.getWidth();
ViewGroup.LayoutParams params = view.getLayoutParams();
params.width = (int)(width * 0.8);
view.setLayoutParams(params);
return new YourViewHolder(view);






share|improve this answer






















  • yes dear i know i should use Horizontal in LinearLayout. but i don't know how can i show next and previous data
    – DJ Al
    Nov 11 at 6:05










  • do you mean, you want to show the partial next and previous data?
    – Rick Sanchez
    Nov 11 at 6:06










  • Yes my friend. such as above image . can you help me?
    – DJ Al
    Nov 11 at 6:09










  • Are you here dear? can you help me?
    – DJ Al
    Nov 11 at 6:20










  • thanks dear, u use int width = recyclerView.getWidth(); code. for use recyclerview i should pass my recyclerview from activity to adapter?
    – DJ Al
    Nov 11 at 6:35










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',
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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246163%2fhow-to-set-horizontal-scroll-with-show-next-and-previous-data-in-recyclerview%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








up vote
0
down vote



accepted










Assuming you need to only show one full item at a time and 2 partial items at both the sides. You can use snaphelper to snap recylerview to nearest item position for having the desired effect. And change the width of your item inside the recycler view in the following way. You need to pass the recyclerView reference inside your adapter to get the width.



@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
final SnapHelper snapHelper = new PagerSnapHelper();
snapHelper.attachToRecyclerView(recyclerView);



and in your onCreateViewHolder change the width of your item.



public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int i) 
final View view =
LayoutInflater.from(parent.getContext())
.inflate(R.layout.your_view, parent, false);
// recyclerView is your passed view.
int width = recyclerView.getWidth();
ViewGroup.LayoutParams params = view.getLayoutParams();
params.width = (int)(width * 0.8);
view.setLayoutParams(params);
return new YourViewHolder(view);






share|improve this answer






















  • yes dear i know i should use Horizontal in LinearLayout. but i don't know how can i show next and previous data
    – DJ Al
    Nov 11 at 6:05










  • do you mean, you want to show the partial next and previous data?
    – Rick Sanchez
    Nov 11 at 6:06










  • Yes my friend. such as above image . can you help me?
    – DJ Al
    Nov 11 at 6:09










  • Are you here dear? can you help me?
    – DJ Al
    Nov 11 at 6:20










  • thanks dear, u use int width = recyclerView.getWidth(); code. for use recyclerview i should pass my recyclerview from activity to adapter?
    – DJ Al
    Nov 11 at 6:35














up vote
0
down vote



accepted










Assuming you need to only show one full item at a time and 2 partial items at both the sides. You can use snaphelper to snap recylerview to nearest item position for having the desired effect. And change the width of your item inside the recycler view in the following way. You need to pass the recyclerView reference inside your adapter to get the width.



@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
final SnapHelper snapHelper = new PagerSnapHelper();
snapHelper.attachToRecyclerView(recyclerView);



and in your onCreateViewHolder change the width of your item.



public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int i) 
final View view =
LayoutInflater.from(parent.getContext())
.inflate(R.layout.your_view, parent, false);
// recyclerView is your passed view.
int width = recyclerView.getWidth();
ViewGroup.LayoutParams params = view.getLayoutParams();
params.width = (int)(width * 0.8);
view.setLayoutParams(params);
return new YourViewHolder(view);






share|improve this answer






















  • yes dear i know i should use Horizontal in LinearLayout. but i don't know how can i show next and previous data
    – DJ Al
    Nov 11 at 6:05










  • do you mean, you want to show the partial next and previous data?
    – Rick Sanchez
    Nov 11 at 6:06










  • Yes my friend. such as above image . can you help me?
    – DJ Al
    Nov 11 at 6:09










  • Are you here dear? can you help me?
    – DJ Al
    Nov 11 at 6:20










  • thanks dear, u use int width = recyclerView.getWidth(); code. for use recyclerview i should pass my recyclerview from activity to adapter?
    – DJ Al
    Nov 11 at 6:35












up vote
0
down vote



accepted







up vote
0
down vote



accepted






Assuming you need to only show one full item at a time and 2 partial items at both the sides. You can use snaphelper to snap recylerview to nearest item position for having the desired effect. And change the width of your item inside the recycler view in the following way. You need to pass the recyclerView reference inside your adapter to get the width.



@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
final SnapHelper snapHelper = new PagerSnapHelper();
snapHelper.attachToRecyclerView(recyclerView);



and in your onCreateViewHolder change the width of your item.



public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int i) 
final View view =
LayoutInflater.from(parent.getContext())
.inflate(R.layout.your_view, parent, false);
// recyclerView is your passed view.
int width = recyclerView.getWidth();
ViewGroup.LayoutParams params = view.getLayoutParams();
params.width = (int)(width * 0.8);
view.setLayoutParams(params);
return new YourViewHolder(view);






share|improve this answer














Assuming you need to only show one full item at a time and 2 partial items at both the sides. You can use snaphelper to snap recylerview to nearest item position for having the desired effect. And change the width of your item inside the recycler view in the following way. You need to pass the recyclerView reference inside your adapter to get the width.



@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
final SnapHelper snapHelper = new PagerSnapHelper();
snapHelper.attachToRecyclerView(recyclerView);



and in your onCreateViewHolder change the width of your item.



public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int i) 
final View view =
LayoutInflater.from(parent.getContext())
.inflate(R.layout.your_view, parent, false);
// recyclerView is your passed view.
int width = recyclerView.getWidth();
ViewGroup.LayoutParams params = view.getLayoutParams();
params.width = (int)(width * 0.8);
view.setLayoutParams(params);
return new YourViewHolder(view);







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 11 at 6:36

























answered Nov 11 at 6:02









Rick Sanchez

728615




728615











  • yes dear i know i should use Horizontal in LinearLayout. but i don't know how can i show next and previous data
    – DJ Al
    Nov 11 at 6:05










  • do you mean, you want to show the partial next and previous data?
    – Rick Sanchez
    Nov 11 at 6:06










  • Yes my friend. such as above image . can you help me?
    – DJ Al
    Nov 11 at 6:09










  • Are you here dear? can you help me?
    – DJ Al
    Nov 11 at 6:20










  • thanks dear, u use int width = recyclerView.getWidth(); code. for use recyclerview i should pass my recyclerview from activity to adapter?
    – DJ Al
    Nov 11 at 6:35
















  • yes dear i know i should use Horizontal in LinearLayout. but i don't know how can i show next and previous data
    – DJ Al
    Nov 11 at 6:05










  • do you mean, you want to show the partial next and previous data?
    – Rick Sanchez
    Nov 11 at 6:06










  • Yes my friend. such as above image . can you help me?
    – DJ Al
    Nov 11 at 6:09










  • Are you here dear? can you help me?
    – DJ Al
    Nov 11 at 6:20










  • thanks dear, u use int width = recyclerView.getWidth(); code. for use recyclerview i should pass my recyclerview from activity to adapter?
    – DJ Al
    Nov 11 at 6:35















yes dear i know i should use Horizontal in LinearLayout. but i don't know how can i show next and previous data
– DJ Al
Nov 11 at 6:05




yes dear i know i should use Horizontal in LinearLayout. but i don't know how can i show next and previous data
– DJ Al
Nov 11 at 6:05












do you mean, you want to show the partial next and previous data?
– Rick Sanchez
Nov 11 at 6:06




do you mean, you want to show the partial next and previous data?
– Rick Sanchez
Nov 11 at 6:06












Yes my friend. such as above image . can you help me?
– DJ Al
Nov 11 at 6:09




Yes my friend. such as above image . can you help me?
– DJ Al
Nov 11 at 6:09












Are you here dear? can you help me?
– DJ Al
Nov 11 at 6:20




Are you here dear? can you help me?
– DJ Al
Nov 11 at 6:20












thanks dear, u use int width = recyclerView.getWidth(); code. for use recyclerview i should pass my recyclerview from activity to adapter?
– DJ Al
Nov 11 at 6:35




thanks dear, u use int width = recyclerView.getWidth(); code. for use recyclerview i should pass my recyclerview from activity to adapter?
– DJ Al
Nov 11 at 6:35

















draft saved

draft discarded
















































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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246163%2fhow-to-set-horizontal-scroll-with-show-next-and-previous-data-in-recyclerview%23new-answer', 'question_page');

);

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







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3