这种实现方法比较简单,但是并不能像是淘票票、猫眼的电影画廊那样,一下子滚动多个item,因为ViewPager本质上就是一次只能划过一个item(此外这种方法,必须设置所有的条目作为缓存mViewPager.setOffscreenPageLimit(TOTAL_COUNT),这样性能低)
一次划过多个item,需要使用RecyclerView+SnapHelp(LinearSnapHelper)来实现,这种效果看上去会更好,具体实现,看这篇博客:实现类似猫眼影片详情页电影海报滚动效果(RcyclerView+LinearSnapHelper )
效果
第一行为ViewPager实现效果
第二行为RcyclerView+LinearSnapHelper 实现效果
一、 布局写法
a. 必须给ViewPager包裹一层布局,例如LinearLayout,并且在LinearLayout添加属性android:clipChildren=”false”
b.ViewPager也必须添加属性android:clipChildren=”false”
c.ViewPager要显示在父布局中间区域,他的宽度不要再math_parent,一般为电影海报的宽度
d.item布局正常写就可以了,只是宽度注意是海报宽度就行,别match_parent
布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.LinearLayoutCompat
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ll_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.custom.view.gallerydemo.MainActivity">
<LinearLayout
android:id=