Reputation: 152
I am trying to achieve something like in the play store
Where all the apps in the view are display 3 apps at a time and the 4th is a preview. while swiping to the left the apps will move and get placed in the respective place making the view cooler.!
Please help me in achieving this view.
public class PageAdapter extends PagerAdapter {
View itemView;
Context context;
LayoutInflater inflater;
ArrayList<String> arrayList = new ArrayList<>();
public PageAdapter(Context context, ArrayList<String> arrayList) {
this.context = context;
this.arrayList = arrayList;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
if (inflater == null)
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.item_page, container, false);
TextView textView = view.findViewById(R.id.text_item);
Log.i("Position>>>>>>>> ", "" + position);
textView.setText(arrayList.get(position));
container.addView(view);
return view;
}
@Override
public int getCount() {
return arrayList.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public void destroyItem(ViewGroup collection, int position, Object view) {
collection.removeView((View) view);
}
View getLayoutView() {
if (itemView != null)
return itemView;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
itemView = inflater.inflate(R.layout.item_page, null);
return itemView;
}
}
Upvotes: 1
Views: 1796
Reputation: 25267
If this is what you are looking for: RecyclerViewSnap
Steps to integrate:
add this line in your dependencies
:
implementation 'com.github.rubensousa:gravitysnaphelper:1.5'
And then simply have this code:
recyclerView.setLayoutManager(new LinearLayoutManager(this,
LinearLayoutManager.HORIZONTAL, false));
SnapHelper snapHelperStart = new GravitySnapHelper(Gravity.START);
snapHelperStart.attachToRecyclerView(startRecyclerView);
To learn more about this Snap Effect, check this Snap to center effect
PS: It is designed to work with RecyclerView and not ViewPager.
Upvotes: 2
Reputation: 1434
It doesn't seem like a view pager. It is recycle view with Horizontal layout manager. View pager are not build and intended to display such content.If you see the tab bar at the top displaying categories i.e comprises the implementation of (tab layout manager with view pager) or the crouser below tablayout showcase viewpager along with pagertransformation. Hence if you want to achieve it, you can easily achieve it using recycle view instead of using view pager.
Upvotes: 1