Figen Güngör
Figen Güngör

Reputation: 12559

How to create this view(at most 4 images in a page then swipe rest as same)?

Let's say I have dynamic number of items coming from server. I can only show 4 items at most in one page. Other pages whould be accesible with swipe Please have a look at the image below. What is the best way to achieve this?

enter image description here

Upvotes: 0

Views: 105

Answers (1)

Amardeep
Amardeep

Reputation: 1434

This could be achieved using

  • View pager
  • Pager Indicator
  • A fragment with four view (Use proportionate layout) or use grid view

Approach

  • The decision on number of pages will lie on the data received from server.

For example: if number of item recieved is 17 the number of pages will be 17/4+ 1(only if 17%4>0)

  • pass the page index to the fragment along with the complete list.

For example if page index in view pager 4

Make sure to keep the check ( index+4<=size of list of item) if (index+4>size of list of item) then the the item to be displayed will start from index and will go on till the size of list. if(index+4<=size of list)the item to be displayed will start from index i.e 4 in this case till next four element in list of items provided to the fragment.

In this way you can always get the required item out of the complete list

Upvotes: 1

Related Questions