A ViewPager performs item animations while scrolling.
Idea from MIUI Rom.
MIUI sample
My Library sample
Add this in your build.gradle
compile 'me.seasonyuu.android:miui-viewpager:1.0.0'-
Add this MIUIViewPager as normal ViewPager
<me.seasonyuu.miuiviewpager.MIUIViewPager android:id="@+id/view_pager" android:layout_width="match_parent" android:layout_height="wrap_content"/>
-
In your
onCreatemethod (oronCreateViewfor a fragment), attach the ViewGroup you want to animate to theViewPagerby using aSparseArray.miuiViewPager.setPagerAttach(new MIUIPagerAttachable() { @Override public SparseArray<ViewGroup> attachViewGroup() { ViewGroup[] viewGroups = adapter.getViewGroups(); // Just get your ViewGroup in ViewPager SparseArray<ViewGroup> attach = new SparseArray<>(); for (int i = 0; i < viewGroups.length; i++) { attach.put(i, viewGroups[i]); } return attach; } });
| Xml | Method | Value and meaning |
|---|---|---|
| app:type | setType | type_in:Animate the page which will be in.(Default value.)type_out:Animate the page which will be in.type_both:Animate both the in and out page. |
| app:item_offset | setItemOffset | Dimension. Offset of different items. |
| app:item_offsetFraction | setItemOffsetFraction | Fraction. Fraction to calculate offset of different items. Fraction * Width will be the item offset.(Default value would be 1/6.) |
To see how these attrs work , please install the sample apk.
- GridView is not recommended, although I had made a support for GridView. It took too much consumption of GPU rendering.
- Only the LinearLayoutManager of RecyclerView is supported, if you use other LayoutManager, please don't attach to ViewPager.
MIUIViewPager library for Android
Copyright (c) 2016 Season Yuu.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

