• Stars
    star
    382
  • Rank 112,241 (Top 3 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 9 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

500px guideview demo

500px-guideview

500px guideview demo

实现原理:一步一步实现500px引导动画 – 酷酷哒


博客主页 | 简书 | 知乎 | 微博 | github

下了500px应用, 瞬间被它的引导动画吸引住了,下面一步一步来实现引导动画

下面的小圆点简单的,就先省略,重点在切换动画


创建viewpager

可以左右随手指滑动的只有底部文字部分,所以ViewPager中存放的布局是底部文字部分 activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff">
    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</RelativeLayout>

先添加viewpager控件

MainActivity.java

//创建adapter
GuideAdapter adapter = new GuideAdapter(getFragmentManager());
//设置viewpager缓存页数,默认的缓存一页,因为引导页共有4页,
//所以设置缓存3页,这样所以page在滑动过程中不会重新创建
viewpager.setOffscreenPageLimit(3);
viewpager.setAdapter(adapter);

MainActivity中,首先获取到xml中的viewpager,为viewpager设置Adapter,并且设置viewpage的缓存页数

   private List<Fragment> fragmentList = new ArrayList<>();

创建了用于填充viewpager的fragmentList

fragment00 = new GuideFragment();
fragment01 = new GuideFragment();
fragment02 = new GuideFragment();
fragment03 = new GuideFragment();

fragmentList.add(fragment00);
fragmentList.add(fragment01);
fragmentList.add(fragment02);
fragmentList.add(fragment03);

初始化fragmentList

 class GuideAdapter extends FragmentPagerAdapter {
        public GuideAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentList.get(position);
        }

        @Override
        public int getCount() {
            return fragmentList.size();
        }
    }

GuideAdapter 继承FragmentPagerAdapter

/**
 * Created by Hanks on 2015/8/13.
 */
public class GuideFragment extends Fragment {
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_guide, container, false);
        return view;
    }
}

在Fragment中只是展示了一下布局 这里写图片描述

运行效果 这里写图片描述


##开始引导动画

//给viewpager设置Pagetransformer
viewpager.setPageTransformer(false, new HKTransformer());
/**
 * by Hanks
 */
class HKTransformer implements ViewPager.PageTransformer {
    @Override
    public void transformPage(View view, float position) {
        Log.i("", "view:    " + view + "position= " + position);
    }
}

观察滑动过程中viewposition的值

从第0页到第1页, 这里写图片描述

这里写图片描述 可以看到4个页面的对应的position 从 0, 1, 2, 3 变化为 -1, 0, 1, 2

然后从第1页滑动到第2页 这里写图片描述

这里写图片描述 可以看到4个页面的对应的position 从 -1, 0, 1, 2 变化为 -2, -1, 0, 1

继续观察可以看到其中的规律,这里不再贴出图片了.

###观察滑动规律 假设4个页面分别为A,B,C,D 只看第0个页面

  • 从 A-B, position: 0 ~ -1
  • 从 B-C, position: -1 ~ -2
  • 从 C-D, position: -2 ~ -3

所以可以以其中一个view的position为标准来确定当前滑动的是哪个页面

/**
 * by Hanks
 */
class HKTransformer implements ViewPager.PageTransformer {
    @Override
    public void transformPage(View view, float position) {
        if (fragment00.getView() == view) {
            Log.i("", "view:    " + view + "position= " + position);
            currentPosition = position;
        }

        if (position < -1) { // [-Infinity,-1)
            // This page is way off-screen to the left.
        } else if (position <= 0) { // [-1,0]
            // Use the default slide transition when moving to the left page
        } else if (position <= 1) { // (0,1]
            // Fade the page out.

            float p = Math.abs(position);
            float f = (1 - p);

            Log.i("", "p= " + p);
            // p : 1~0
            // f : 0~1


            if (-1 < currentPosition && currentPosition <= 0) {
               // A ~ B 之间的动画


            } else if (-2 < currentPosition && currentPosition <= -1) {
                //B ~  C 之间的动画


            } else if (-3 < currentPosition && currentPosition <= -2) {
                //C ~  D 之间的动画

            }


        } else { // (1,+Infinity]
            // This page is way off-screen to the right.
        }
    }
}

在position处于**(0,1]时,表示两个页面正在滑动切换,可以打印一下看看,然后就是基于上面的规律, 根据currentPosition**来判断是从在哪两个页面之间滑动

###开始动画

####A~B界面的动画

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff">


    <ImageView
        android:id="@+id/iv_device"
        android:layout_width="340dp"
        android:layout_height="500dp"
        android:layout_centerInParent="true"
        android:scaleType="centerInside"
        android:src="@drawable/tour_device" />

    <ImageView
        android:id="@+id/iv_initial_phone"
        android:layout_width="200dp"
        android:layout_height="400dp"
        android:layout_centerInParent="true"
        android:scaleType="centerCrop"
        android:src="@drawable/tour_initial_photo" />

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></android.support.v4.view.ViewPager>


</RelativeLayout>

一个手机边框 :

  • scaleX : 1 ~ 2
  • alpha : 1 ~ 0

中间"大人小孩"图片 : scaleX : 1 ~ 0.5 scaleY : 1 ~ 0.5 translationY: 0 ~ -600

评论模块: scaleX : 2 ~ 1 scaleY : 2 ~ 1 translationY: 800 ~ 0 alpha : ~ 1

iv_initial_phone.setTranslationY(-600 * f);
iv_initial_phone.setScaleX(0.5f * p + 0.5f);
iv_initial_phone.setScaleY(0.5f * p + 0.5f);
iv_device.setScaleX(1 + 2 * f);

//仔细观察iv_device是在滑到中间时就完全alpha=0了
if (p > 0.5 && p <= 1) {
    iv_device.setAlpha(2 * p - 1);
} else {
    iv_device.setAlpha(0f);
}
ll_comments.setTranslationY(800 * p);
ll_comments.setAlpha(f);
ll_comments.setScaleX(2 - f);
ll_comments.setScaleY(2 - f);

运行效果
这里写图片描述

####B~C界面的动画 布局文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff">

    <LinearLayout
        android:id="@+id/ll_comments"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:orientation="vertical">

        <TextView
            android:layout_width="200dp"
            android:layout_height="63dp"
            android:layout_gravity="right"
            android:drawableLeft="@drawable/tour_avatar1"
            android:drawablePadding="8dp"
            android:gravity="center_vertical|left"
            android:text="Kaitlyn 收藏了\n您的照片\n刚刚"
            android:textColor="#111"
            android:textSize="14sp" />

        <TextView
            android:layout_width="200dp"
            android:layout_height="63dp"
            android:layout_gravity="left"
            android:drawablePadding="8dp"
            android:drawableRight="@drawable/tour_avatar2"
            android:gravity="center_vertical|right"
            android:text="Adam 评论了\n您的照片\n刚刚"
            android:textColor="#111"
            android:textSize="14sp" />

        <TextView
            android:layout_width="200dp"
            android:layout_height="63dp"
            android:layout_gravity="right"
            android:drawableLeft="@drawable/tour_avatar3"
            android:drawablePadding="8dp"
            android:gravity="center_vertical|left"
            android:text="Kaitlyn 收藏了\n您的照片\n刚刚"
            android:textColor="#111"
            android:textSize="14sp" />

        <TextView
            android:layout_width="200dp"
            android:layout_height="63dp"
            android:layout_gravity="left"
            android:drawablePadding="8dp"
            android:drawableRight="@drawable/tour_avatar4"
            android:gravity="right|center_vertical"
            android:text="Adam 评论了\n您的照片\n刚刚"
            android:textColor="#111"
            android:textSize="14sp" />
    </LinearLayout>
    <LinearLayout
        android:id="@+id/ll_rows"
        android:layout_width="600dp"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:gravity="center_horizontal"
        android:orientation="vertical">

        <ImageView
            android:layout_width="600dp"
            android:layout_height="72dp"
            android:scaleType="centerCrop"
            android:src="@drawable/row1" />

        <ImageView
            android:layout_width="600dp"
            android:layout_height="72dp"
            android:scaleType="centerCrop"
            android:src="@drawable/row2" />

        <ImageView
            android:layout_width="843dp"
            android:layout_height="72dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginLeft="5.5dp"
            android:scaleType="fitXY"
            android:src="@drawable/row3" />

        <ImageView
            android:layout_width="600dp"
            android:layout_height="72dp"
            android:scaleType="centerCrop"
            android:src="@drawable/row4" />

        <ImageView
            android:layout_width="600dp"
            android:layout_height="72dp"
            android:scaleType="centerCrop"
            android:src="@drawable/row5" />

        <ImageView
            android:layout_width="600dp"
            android:layout_height="72dp"
            android:scaleType="centerCrop"
            android:src="@drawable/row6" />

        <ImageView
            android:layout_width="600dp"
            android:layout_height="72dp"
            android:scaleType="centerCrop"
            android:src="@drawable/row7" />

        <ImageView
            android:layout_width="600dp"
            android:layout_height="72dp"
            android:scaleType="centerCrop"
            android:src="@drawable/row8" />

        <ImageView
            android:layout_width="600dp"
            android:layout_height="72dp"
            android:scaleType="centerCrop"
            android:src="@drawable/row9" />
    </LinearLayout>
    <ImageView
        android:id="@+id/iv_device"
        android:layout_width="340dp"
        android:layout_height="500dp"
        android:layout_centerInParent="true"
        android:scaleType="centerInside"
        android:src="@drawable/tour_device" />


    <ImageView
        android:id="@+id/iv_initial_phone"
        android:layout_width="200dp"
        android:layout_height="400dp"
        android:layout_centerInParent="true"
        android:scaleType="centerCrop"
        android:src="@drawable/tour_initial_photo" />

    <ImageView
        android:id="@+id/iv_final_photo"
        android:layout_width="48dp"
        android:layout_height="72dp"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="144dp"
        android:scaleType="centerCrop"
        android:src="@drawable/tour_final_photo" />


    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></android.support.v4.view.ViewPager>


</RelativeLayout>

"大人小孩"图片: translationY : -600 ~ -900

评论模块: alpha : 1 ~ 0

横条图片模块: translationY : -1000 ~ 0 alpha : 1 ~ 0.5

横条图片中间图片(这是一个单独的图片,后面的动画用到): translationY : -1000 ~ 0 alpha : 0.5 ~ 1

 iv_initial_phone.setTranslationY(-600 + -300 * f);

ll_comments.setAlpha(p);

ll_rows.setTranslationY(-1000 * p);
ll_rows.setAlpha(0.5f + 0.5f * f);

iv_final_photo.setTranslationY(-1000 * p);
iv_final_photo.setAlpha(0.5f + 0.5f * f);

效果: 这里写图片描述

####C~D界面的动画

设置缩放中心点

iv_final_photo.setPivotY(0f);
iv_final_photo.setPivotX(iv_final_photo.getWidth() / 2);

最后图片: scaleX : 1 ~ 3 scaleY : 1 ~ 3

横条图片模块 *奇数行向右移动, translationX : 0 ~ -100 *偶数行向左移动, translationX : 0 ~ 100

头像模块: translationY : -300 ~ 0

注册按钮 translationX : 300 ~ 0

iv_final_photo.setScaleX(1 + 3 * f); //1~3
iv_final_photo.setScaleY(1 + 3 * f); //1~3

for (int i = 0; i < ll_rows.getChildCount(); i++) {
   View child = ll_rows.getChildAt(i);
   child.setAlpha(p);
   if (i % 2 == 0) {
       child.setTranslationX(100 * f);
   } else {
       child.setTranslationX(-100 * f);
   }
}

tv_avatar_you.setTranslationY(-300 + 300 * f);

tv_register.setTranslationY(300 - 300 * f);

运行结果: 这里写图片描述


###最后的模糊效果 看到一篇博客 (中文翻译版)讲解了500px的模糊效果

项目地址:https://github.com/500px/500px-android-blur

在build.gradle中添加

renderscriptTargetApi 18
renderscriptSupportModeEnabled true

将BlurringView.java复制到项目目录

使用BlurringView,

   <hanks.com.customview.BlurringView
        android:id="@+id/blurringView"
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:layout_alignParentBottom="true"
        app:blurRadius="11"
        app:downsampleFactor="6"
        app:overlayColor="#99FFFFFF"
        >
    </hanks.com.customview.BlurringView>
 View blurredView = findViewById(R.id.blurredView);
 blurringView.setBlurredView(blurredView);
 blurringView.invalidate();

最终的xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="#fff"
    android:orientation="vertical">

    <RelativeLayout
        android:id="@+id/blurredView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:id="@+id/ll_comments"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:orientation="vertical">

            <TextView
                android:layout_width="200dp"
                android:layout_height="63dp"
                android:layout_gravity="right"
                android:drawableLeft="@drawable/tour_avatar1"
                android:drawablePadding="8dp"
                android:gravity="center_vertical|left"
                android:text="Kaitlyn 收藏了\n您的照片\n刚刚"
                android:textColor="#111"
                android:textSize="14sp" />

            <TextView
                android:layout_width="200dp"
                android:layout_height="63dp"
                android:layout_gravity="left"
                android:drawablePadding="8dp"
                android:drawableRight="@drawable/tour_avatar2"
                android:gravity="center_vertical|right"
                android:text="Adam 评论了\n您的照片\n刚刚"
                android:textColor="#111"
                android:textSize="14sp" />

            <TextView
                android:layout_width="200dp"
                android:layout_height="63dp"
                android:layout_gravity="right"
                android:drawableLeft="@drawable/tour_avatar3"
                android:drawablePadding="8dp"
                android:gravity="center_vertical|left"
                android:text="Kaitlyn 收藏了\n您的照片\n刚刚"
                android:textColor="#111"
                android:textSize="14sp" />

            <TextView
                android:layout_width="200dp"
                android:layout_height="63dp"
                android:layout_gravity="left"
                android:drawablePadding="8dp"
                android:drawableRight="@drawable/tour_avatar4"
                android:gravity="right|center_vertical"
                android:text="Adam 评论了\n您的照片\n刚刚"
                android:textColor="#111"
                android:textSize="14sp" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/ll_rows"
            android:layout_width="600dp"
            android:layout_height="match_parent"
            android:layout_centerHorizontal="true"
            android:gravity="center_horizontal"
            android:orientation="vertical">

            <ImageView
                android:layout_width="600dp"
                android:layout_height="72dp"
                android:scaleType="centerCrop"
                android:src="@drawable/row1" />

            <ImageView
                android:layout_width="600dp"
                android:layout_height="72dp"
                android:scaleType="centerCrop"
                android:src="@drawable/row2" />

            <ImageView
                android:layout_width="843dp"
                android:layout_height="72dp"
                android:layout_gravity="center_horizontal"
                android:layout_marginLeft="5.5dp"
                android:scaleType="fitXY"
                android:src="@drawable/row3" />

            <ImageView
                android:layout_width="600dp"
                android:layout_height="72dp"
                android:scaleType="centerCrop"
                android:src="@drawable/row4" />

            <ImageView
                android:layout_width="600dp"
                android:layout_height="72dp"
                android:scaleType="centerCrop"
                android:src="@drawable/row5" />

            <ImageView
                android:layout_width="600dp"
                android:layout_height="72dp"
                android:scaleType="centerCrop"
                android:src="@drawable/row6" />

            <ImageView
                android:layout_width="600dp"
                android:layout_height="72dp"
                android:scaleType="centerCrop"
                android:src="@drawable/row7" />

            <ImageView
                android:layout_width="600dp"
                android:layout_height="72dp"
                android:scaleType="centerCrop"
                android:src="@drawable/row8" />

            <ImageView
                android:layout_width="600dp"
                android:layout_height="72dp"
                android:scaleType="centerCrop"
                android:src="@drawable/row9" />
        </LinearLayout>


        <ImageView
            android:id="@+id/iv_device"
            android:layout_width="340dp"
            android:layout_height="500dp"
            android:layout_centerInParent="true"
            android:scaleType="centerInside"
            android:src="@drawable/tour_device" />

        <ImageView
            android:id="@+id/iv_initial_phone"
            android:layout_width="200dp"
            android:layout_height="400dp"
            android:layout_centerInParent="true"
            android:scaleType="centerCrop"
            android:src="@drawable/tour_initial_photo" />

        <ImageView
            android:id="@+id/iv_final_photo"
            android:layout_width="48dp"
            android:layout_height="72dp"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="144dp"
            android:scaleType="centerCrop"
            android:src="@drawable/tour_final_photo" />

        <TextView
            android:id="@+id/tv_avatar_you"
            android:layout_width="wrap_content"
            android:layout_height="90dp"
            android:layout_centerHorizontal="true"
            android:drawableTop="@drawable/tour_avatar_you"
            android:gravity="center"
            android:paddingTop="30dp"
            android:text="您收藏这张照片\n刚刚"
            android:textColor="#222"
            android:textSize="10sp" />
    </RelativeLayout>

    <hanks.com.guideview.BlurringView
        android:id="@+id/blurringView"
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:layout_alignParentBottom="true"
        app:blurRadius="11"
        app:downsampleFactor="6"
        app:overlayColor="#99FFFFFF"
        >

    </hanks.com.guideview.BlurringView>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        ></android.support.v4.view.ViewPager>


    <TextView
        android:id="@+id/tv_register"
        android:layout_width="80dp"
        android:layout_height="25dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="15dp"
        android:background="#2595ec"
        android:gravity="center"
        android:text="注册"
        android:textColor="#fff"
        android:textSize="12sp" />

</RelativeLayout>
package hanks.com.guideview;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

/**
 * by Hanks
 */
public class MainActivity extends FragmentActivity {

    private ViewPager viewpager;
    private ImageView iv_device, iv_initial_phone;
    private ImageView iv_final_photo;
    private List<Fragment> fragmentList = new ArrayList<>();
    private LinearLayout ll_rows, ll_comments;
    private float currentPosition = 0;
    private GuideFragment fragment00, fragment01, fragment02, fragment03;
    private TextView tv_avatar_you;
    private TextView tv_register;

    private BlurringView blurringView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息栏
        setContentView(R.layout.activity_main);
        setFullscreen();

        fragment00 = new GuideFragment();
        fragment01 = new GuideFragment();
        fragment02 = new GuideFragment();
        fragment03 = new GuideFragment();

        fragmentList.add(fragment00);
        fragmentList.add(fragment01);
        fragmentList.add(fragment02);
        fragmentList.add(fragment03);


        viewpager = (ViewPager) findViewById(R.id.viewpager);
        iv_device = (ImageView) findViewById(R.id.iv_device);
        iv_final_photo = (ImageView) findViewById(R.id.iv_final_photo);
        tv_avatar_you = (TextView) findViewById(R.id.tv_avatar_you);
        tv_register = (TextView) findViewById(R.id.tv_register);

        blurringView = (BlurringView) findViewById(R.id.blurringView);

        ll_rows = (LinearLayout) findViewById(R.id.ll_rows);
        ll_comments = (LinearLayout) findViewById(R.id.ll_comments);

        iv_initial_phone = (ImageView) findViewById(R.id.iv_initial_phone);

        View blurredView = findViewById(R.id.blurredView);
        blurringView.setBlurredView(blurredView);

        //创建adapter
        GuideAdapter adapter = new GuideAdapter(getSupportFragmentManager());
        //设置viewpager缓存页数,默认的缓存一页,因为引导页共有4页,
        //所以设置缓存3页,这样所以page在滑动过程中不会重新创建
        viewpager.setOffscreenPageLimit(3);
        viewpager.setAdapter(adapter);
        viewpager.setPageTransformer(true, new HKTransformer());
    }

    private void setFullscreen() {
        View decorView = getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        decorView.setSystemUiVisibility(uiOptions);
    }

    class GuideAdapter extends FragmentPagerAdapter {
        public GuideAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentList.get(position);
        }

        @Override
        public int getCount() {
            return fragmentList.size();
        }
    }


    /**
     * by Hanks
     */
    class HKTransformer implements ViewPager.PageTransformer {
        @Override
        public void transformPage(View view, float position) {
            if (fragment00.getView() == view) {
                Log.i("", "view:    " + view + "position= " + position);
                currentPosition = position;
            }

            blurringView.invalidate();

            if (position < -1) { // [-Infinity,-1)
                // This page is way off-screen to the left.
            } else if (position <= 0) { // [-1,0]
                // Use the default slide transition when moving to the left page
            } else if (position <= 1) { // (0,1]
                // Fade the page out.

                float p = Math.abs(position);
                float f = (1 - p);

                Log.i("", "p= " + p);
                // p : 1~0
                // f : 0~1

                iv_final_photo.setPivotY(0f);
                iv_final_photo.setPivotX(iv_final_photo.getWidth() / 2);

                if (-1 < currentPosition && currentPosition <= 0) {
                    // A ~ B 界面的动画

                    iv_initial_phone.setTranslationY(-600 * f);
                    iv_initial_phone.setScaleX(0.5f * p + 0.5f);
                    iv_initial_phone.setScaleY(0.5f * p + 0.5f);
                    iv_device.setScaleX(1 + 2 * f);

                    if (p > 0.5 && p <= 1) {
                        iv_device.setAlpha(2 * p - 1);
                    } else {
                        iv_device.setAlpha(0f);
                    }

                    ll_comments.setTranslationY(800 * p);
                    ll_comments.setAlpha(f);
                    ll_comments.setScaleX(2 - f);
                    ll_comments.setScaleY(2 - f);

                    ll_rows.setTranslationY(-1000 - 500 * p);
                    ll_rows.setAlpha(0.5f);
                    iv_final_photo.setTranslationY(-1000 - 500 * p);
                    iv_final_photo.setAlpha(0.5f);

                    tv_avatar_you.setTranslationY(-300);

                    tv_register.setTranslationY(300);

                } else if (-2 < currentPosition && currentPosition <= -1) {
                    // B ~ C 界面的动画

                    iv_initial_phone.setTranslationY(-600 + -300 * f);

                    ll_comments.setAlpha(p);

                    ll_rows.setTranslationY(-1000 * p);
                    ll_rows.setAlpha(0.5f + 0.5f * f);

                    iv_final_photo.setTranslationY(-1000 * p);
                    iv_final_photo.setAlpha(0.5f + 0.5f * f);

                    tv_avatar_you.setTranslationY(-300);
                    tv_register.setTranslationY(300);
                } else if (-3 < currentPosition && currentPosition <= -2) {
                    // C ~ D 界面的动画


                    iv_final_photo.setScaleX(1 + 3 * f); //1~3
                    iv_final_photo.setScaleY(1 + 3 * f); //1~3

                    for (int i = 0; i < ll_rows.getChildCount(); i++) {
                        View child = ll_rows.getChildAt(i);
                        child.setAlpha(p);
                        if (i % 2 == 0) {
                            child.setTranslationX(100 * f);
                        } else {
                            child.setTranslationX(-100 * f);
                        }
                    }

                    tv_avatar_you.setTranslationY(-300 + 300 * f);

                    tv_register.setTranslationY(300 - 300 * f);
                }


            } else { // (1,+Infinity]
                // This page is way off-screen to the right.
            }
        }
    }
}

More Repositories

1

HTextView

Animation effects to text, not really textview
Java
5,620
star
2

SmallBang

twitter like animation for any view 💓
Java
1,002
star
3

PasscodeView

Material Design PasscodeView for Android.
Java
539
star
4

AnimateCheckBox

A custom view in Android with a animation when CheckBox status changed
Java
472
star
5

Conquer

A todo list app base Material Design
Java
433
star
6

SwipeRefreshLayout

谷歌的下拉刷新,新的界面效果
Java
368
star
7

LineHeightEditText

Fix edittext lineHeight and cursor length when set lineSpacingExtra or lineSpacingMultiplier
Java
203
star
8

hydrogenApp

hydrogen is a pluggable android app
Lua
170
star
9

ScrollViewOnTouch

仿百度助手头部搜索框缩放.
Java
139
star
10

luaDevAndroid

dev android use lua language
Java
135
star
11

SelectPicture

仿微信选择图片拍照
Java
129
star
12

RxSerach

RxSerach
Java
117
star
13

NumberAnimation

number view with 'add' animation
Java
61
star
14

PhotoViewer

imageView transition animation
Java
46
star
15

juejin_flutter

juejin client ui power by flutter
Dart
44
star
16

ToolBar

带动画的ActionBar --------- ToolBar(兼容低版本)
Java
43
star
17

ViewPager-Listview-item-Viewpager-

Viewpager中嵌套Listview,而且Listview的item中夹杂ViewPage
Java
43
star
18

MaterialCheckBox

Custom view to implement CheckBox in Material Design to 14+
Java
30
star
19

WeixinEye

高仿微信下拉小眼睛动画
Java
27
star
20

Hrn

hanks react-native-demo
JavaScript
23
star
21

SlideLayout

控制View的OnClick OnTouch来实现LsitView的Item的侧滑出现删除
Java
23
star
22

PlayerButton

用于播放音频文件的自定义按钮,有进度条,可暂停
Java
19
star
23

SelectorButton

Custom button that can implement click effect don't need create a selector.xml
Java
19
star
24

capturedata

tools to capture network data 抓包工具总结
19
star
25

FlyWoo

A android app can use the wifi hotspot transmit data without mobile network
Java
17
star
26

OpAnimateView

Material Design View with Animation
Java
14
star
27

BottomLayout

自定义组合控件,底部多按钮切换
Java
10
star
28

DeletableEditText

Custom Edittext with a delete button
Java
8
star
29

AndroidDesignPattern

source code in <<Android 源码设计模式解析与实战>>
Java
8
star
30

233333

鬼畜表情包 react-native版
JavaScript
7
star
31

NestedScroll

Java
6
star
32

eye-video

Vue
6
star
33

RecylerView

Swipe the item of RecylerView and Drag to sort item
Java
6
star
34

SuperRecyclerView

Just like super man :octocat:
Java
5
star
35

LuajAndroid

Android use Luaj
Java
4
star
36

GenerateBanner

generate a beautiful banner by canvas
JavaScript
3
star
37

MoblieSafe

just for learn
Java
2
star
38

MaterialDesign

Design support library with material
Java
2
star
39

TextAnimation

Java
2
star
40

apkInstaller

silent to install apks
Java
2
star
41

LoadingLayout

layout with three children, normal loading selected status
Java
2
star
42

buildluajava

build luajava so files in AS 2.3.2
C
2
star
43

U

:octocat:
Java
2
star
44

RxSimple

Java
2
star
45

themedemo

themedemo
Java
2
star
46

QRcode-scanning

use ZXing to recognize QRcode
Java
2
star
47

videowallpaper

1
star
48

blog-comment

1
star
49

blog_golang

blog api base on golang
Go
1
star
50

ActivityResultManager

convert `activity.startActivityForResult` to callback
Kotlin
1
star
51

lua-5.3.4-64_32

C
1
star
52

joke

joke data form qiqu.uc.cn
Vue
1
star
53

folder-widget

1
star
54

CircleImageView

simple to implemente a circle ImageView with border
Java
1
star
55

resume

a resume app running on android
Java
1
star
56

PythonBlog

Just learn Python
CSS
1
star
57

12306

find available ticket
1
star
58

hanks-zyh.github.io

blog
HTML
1
star
59

hkalbum

a android library to pick pictures form album or camera
1
star
60

AllApplication

Java
1
star
61

lua_into_android

lua 嵌入 Android
C
1
star
62

Flask-blog

a blog base on flask
HTML
1
star
63

AutoPictureforWord

给文字自动配图片
Java
1
star