0

I am trying to make viewpager work like one in google playstore in movies,music,books section.

Below is screenshot of one:

enter image description here

This is screenshot of viewpager i want:

enter image description here

below is my xml code:

 <android.support.v4.view.ViewPager
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/vp"
        android:layout_width="match_parent"
        android:layout_height="160dp"
        android:layout_marginBottom="5dp">
    </android.support.v4.view.ViewPager>

below is java code:

  ViewPager vp;
    int mResources[]= {R.drawable.b,R.drawable.c,R.drawable.d};
    vp = (ViewPager)findViewById(R.id.vp);
    vp.setPageMargin(-10);
    vp.setAdapter(new ViewPageAdapter(ViewPagerActivity.this,mResources));

below is xml for single item:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:background="#eee"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="match_parent"
android:layout_height="220dp">

<android.support.v7.widget.CardView
    android:elevation="10dp"
    app:cardCornerRadius="10dp"
    android:layout_margin="10dp"
    android:layout_width="match_parent"
    android:layout_height="200dp">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:src="@drawable/c"
        android:id="@+id/imageView" />

</android.support.v7.widget.CardView>

Thanks in advance for help

Rohit Lalwani
  • 529
  • 7
  • 14

2 Answers2

0

If I'm not mistaken, you want a ViewPager whose next/previous items partly showing.

If so, set minus page margin to the viewPager by ViewPager.setPageMargin(int), and add (positive) margins to each item's left and right.

I hope it'll help you.

Yuta
  • 286
  • 1
  • 7
0

You should use RecyclerView with LinearLayoutManager with a horizontal orientation. This post should answer your question. ViewPager is typically used in conjunction with entire fragments as opposed to scrolling components within those fragments according to the documentation.

Ben Lewis
  • 213
  • 1
  • 9