DonLiangGit / Android-Copymao

Android App Implementations inspired by other apps
8 stars 2 forks source link

Parallax Effect in ViewPager #5

Open DonLiangGit opened 9 years ago

DonLiangGit commented 9 years ago

Fragment Pager Parallax Solution: mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float percent, int offset) { int totalPages = 4; float Percentage = ((position+percent)_100 / totalPages); mImageDrawable.setLevel((int)(400_Percentage)); } }

The key point is that: set a clipdrawable then set its level based on the percentage of page scrolling.

DonLiangGit commented 9 years ago

Background Parallax Solution: Define a ScrollView in the background layer, the viewpager is defined in another layer which is inflated by Layoutinflater. (Not accurate) / Alternative method: make a ImageView set its scale type then make the imageview translationY direction.