Skip to content

Commit

Permalink
加入viewpager切换动画
Browse files Browse the repository at this point in the history
  • Loading branch information
郭文明 committed Sep 5, 2016
1 parent 5a9f0bd commit b8803a7
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.Window;

import com.wenming.weiswift.R;
import com.wenming.weiswift.ui.common.StatusBarUtils;
import com.wenming.weiswift.ui.login.fragment.home.imagedetaillist.animation.RotateDownPageTransformer;
import com.wenming.weiswift.ui.login.fragment.home.imagedetaillist.animation.ZoomOutPageTransformer;

import java.util.ArrayList;

Expand Down Expand Up @@ -57,6 +60,7 @@ protected void onCreate(Bundle savedInstanceState) {
mAdapter = new ViewPagerAdapter(mDatas, this);
mAdapter.setOnSingleTagListener(this);
mViewPager.setAdapter(mAdapter);
mViewPager.setPageTransformer(true,new ZoomOutPageTransformer());
if (mImgNum == 1) {
mImageDetailTopBar.setPageNumVisible(View.GONE);
} else {
Expand Down Expand Up @@ -88,6 +92,7 @@ public void onClick(View view) {
}
});


StatusBarUtils.from(this)
.setTransparentStatusbar(true)
.setStatusBarColor(getResources().getColor(R.color.black))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.wenming.weiswift.ui.login.fragment.home.imagedetaillist.animation;

import android.support.v4.view.ViewPager;
import android.view.View;

public class DepthPageTransformer implements ViewPager.PageTransformer {
private static final float MIN_SCALE = 0.75f;

public void transformPage(View view, float position) {
int pageWidth = view.getWidth();

if (position < -1) { // [-Infinity,-1)
// This page is way off-screen to the left.
view.setAlpha(0);

} else if (position <= 0) { // [-1,0]
// Use the default slide transition when moving to the left page
view.setAlpha(1);
view.setTranslationX(0);
view.setScaleX(1);
view.setScaleY(1);

} else if (position <= 1) { // (0,1]
// Fade the page out.
view.setAlpha(1 - position);

// Counteract the default slide transition
view.setTranslationX(pageWidth * -position);

// Scale the page down (between MIN_SCALE and 1)
float scaleFactor = MIN_SCALE
+ (1 - MIN_SCALE) * (1 - Math.abs(position));
view.setScaleX(scaleFactor);
view.setScaleY(scaleFactor);

} else { // (1,+Infinity]
// This page is way off-screen to the right.
view.setAlpha(0);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.wenming.weiswift.ui.login.fragment.home.imagedetaillist.animation;

import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;

public class RotateDownPageTransformer implements ViewPager.PageTransformer {

private static final float ROT_MAX = 20.0f;
private float mRot;


public void transformPage(View view, float position) {

Log.e("TAG", view + " , " + position + "");

if (position < -1) { // [-Infinity,-1)
// This page is way off-screen to the left.
view.setRotation(0);

} else if (position <= 1) // a页滑动至b页 ; a页从 0.0 ~ -1 ;b页从1 ~ 0.0
{ // [-1,1]
// Modify the default slide transition to shrink the page as well
if (position < 0) {

mRot = (ROT_MAX * position);
view.setPivotX(view.getMeasuredWidth() * 0.5f);
view.setPivotY(view.getMeasuredHeight());
view.setRotation(mRot);
} else {

mRot = (ROT_MAX * position);
view.setPivotX(view.getMeasuredWidth() * 0.5f);
view.setPivotY(view.getMeasuredHeight());
view.setRotation(mRot);
}

// Scale the page down (between MIN_SCALE and 1)

// Fade the page relative to its size.

} else { // (1,+Infinity]
// This page is way off-screen to the right.
view.setRotation(0);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.wenming.weiswift.ui.login.fragment.home.imagedetaillist.animation;

import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;

public class ZoomOutPageTransformer implements ViewPager.PageTransformer
{
private static final float MIN_SCALE = 0.85f;
private static final float MIN_ALPHA = 0.5f;

public void transformPage(View view, float position)
{
int pageWidth = view.getWidth();
int pageHeight = view.getHeight();

Log.e("TAG", view + " , " + position + "");

if (position < -1)
{ // [-Infinity,-1)
// This page is way off-screen to the left.
view.setAlpha(0);

} else if (position <= 1) //a页滑动至b页 ; a页从 0.0 -1 ;b页从1 ~ 0.0
{ // [-1,1]
// Modify the default slide transition to shrink the page as well
float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
float vertMargin = pageHeight * (1 - scaleFactor) / 2;
float horzMargin = pageWidth * (1 - scaleFactor) / 2;
if (position < 0)
{
view.setTranslationX(horzMargin - vertMargin / 2);
} else
{
view.setTranslationX(-horzMargin + vertMargin / 2);
}

// Scale the page down (between MIN_SCALE and 1)
view.setScaleX(scaleFactor);
view.setScaleY(scaleFactor);

// Fade the page relative to its size.
view.setAlpha(MIN_ALPHA + (scaleFactor - MIN_SCALE)
/ (1 - MIN_SCALE) * (1 - MIN_ALPHA));

} else
{ // (1,+Infinity]
// This page is way off-screen to the right.
view.setAlpha(0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ public void setNightMode(String message) {
private void initContent() {
boolean isNightMode = (boolean) SharedPreferencesUtil.get(mContext, "setNightMode", false);
mCheckBox.setChecked(isNightMode);
//User user = mAct
//setUserDetail();
setUserDetail(mUser);
}

@Override
Expand Down

0 comments on commit b8803a7

Please sign in to comment.