一步一步实现500px引导动画 -- 酷酷哒

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

转载请注明出处 : http://blog.csdn.net/hpu_zyh/article/details/47749859

博客主页 | 简书 | 知乎 | 微博 | 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.
            }
        }
    }
}

源代码下载:https://github.com/hanks-zyh/500px-guideview

版权声明:本文为博主原创文章,未经博主允许不得转载。 转载请标明出处 http://blog.csdn.net/hpu_zyh

时间: 2024-08-25 21:58:54

一步一步实现500px引导动画 -- 酷酷哒的相关文章

融合应用11.1.8安装,一步一步的引导

融合应用11.1.8安装,一步一步的引导 融合应用11.1.8 安装并不是简单的与电子商务套件11 i / R12安装. 所以我们需要安装划分为许多步骤. 请注意,11.1.8 11.1.7总统发布供应是几乎相同的. 在同一时间的步骤和一些组件11.1.6和11.1.5相比有所不同. 这里我们有实际使用同一个11.1.7步骤在这里11.1.8指导和将提到11.1.7相比无论我们看到一个不同的步骤. 注意:如果您正在寻找融合应用程序 11.1.6 安装步骤,那么你可以参考以下链接. http://

一步一步带你实现ListView动画展开布局, ExpandableLayout实现

做项目的时候,需要一种listview,点击item的时候在item的下方展开一个菜单,于是在gituhub上找到了源码: ExpandableLayout,地址: https://github.com/traex/ExpandableLayout 这个项目实现的效果如下: 上一篇我已经讲解了这个项目的原理,有兴趣的同学可以点击这里看源码解析: http://blog.csdn.net/u010335298/article/details/51193565 今天我们主要是从开发者的角度一步一步的

手把手教你实现一个引导动画

前言 最近看了一些文章,知道了实现引导动画的基本原理,所以决定来自己亲手做一个通用的引导动画类. 我们先来看一下具体的效果:点这里 原理 通过维护一个Modal实例,使用Modal的mask来隐藏掉页面的其他元素. 根据用户传入的需要引导的元素列表,依次来展示元素.展示元素的原理:通过cloneNode来复制一个当前要展示元素的副本,通过当前元素的位置信息来展示副本,并且通过z-index属性来让其在ModalMask上方展示.大致代码如下: const newEle = target.clon

一步一步教你用Swift开发俄罗斯方块:No.7 下落机制

上一章节我们完成了shape的建立,现在游戏里面的元素(blocks,shapes)都已经完成了,背景也搭好了(array2D),让我们开始制定游戏规则吧.首先就是需要让我们的shape掉下来,还记得我们刚开始的时候每个600毫秒要刷新一下屏幕呢?那会还有一个closure我们都不太明白是干嘛用的,马上就知道了. 好了,今天章节过后,你的程序运行起来应该是这样的: 让我们来修改代码吧,这次要修改的代码比较多,而且没有上一章节那样重复的工作.不用太过担心,我们一步一步来: 在#1, 函数在执行时会

【转】朱兆祺带你一步一步学习嵌入式(连载)

原文网址:http://bbs.elecfans.com/jishu_357014_2_1.html#comment_top  从最初涉及嵌入式Linux开始到现在,深深的知道嵌入式的每一步学习都是举步维艰.从去年11月份开始,我就着手整理各种学习资料,希望推动嵌入式学习的前进贡献自己微不足道的一份力量.从去年到现在,将C语言的学习经验整理成<攻破C语言笔试与机试陷阱及难点>(现在仍在更新),这份资料已经在电子发烧友论坛的单片机论坛连载(http://bbs.elecfans.com/jish

教你一步一步实现图标无缝变形切换

我的简书同步发布:教你一步一步实现图标无缝变形切换 ?欢迎打赏? 转载请注明出处:[huachao1001的专栏:http://blog.csdn.net/huachao1001] 本来这篇文章几天前就应该写好并发布出来的,由于要写小论文,被导师劈头盖脸的骂了几天,一直在搞论文,耽误了博文的编写.今天终于把小论文给投出去了,终于可以好好写博客了! 在上一篇文章<酷炫的Activity切换动画,打造更好的用户体验 >中,我们感受到了过渡切换动画带来的不一样的用户体验.如何你还意犹未尽,那么今天我

jQuery一步一步实现跨浏览器的可编辑表格,支持IE、Firefox、Safari、

脚 本 之 家 www.jb51.net 脚本云 专题 素材下载 电子书 软件下载 源码下载 服务器常用软件 a5交易 首页 网页制作 脚本专栏 脚本下载 网络编程 数据库 CMS教程 电子书籍 平面设计 媒体动画 操作系统 网站运营 网络安全 YUI.Ext相关 prototype jquery dojo json lib_js js面向对象 extjs Mootools Seajs 其它 特色栏目: vbscript 正则表达式 javascript 批处理 服务器软件 素材下载 低价出售流

一步一步安装UEFI分区方式的windows 10 企业版

http://bbs.pcbeta.com/viewthread-1616698-1-1.html 发现很多坛友不会安装UEFI分区的windows 10 从启动设置,到分区,到最后的引导与激活都是很大的问题. 在我看来这是最不容易出错的安装方式适合于刚刚上手的菜鸟,自己按照图片一步一步的就可以安装上原版加密镜像.我有原版情节,所用最下面放上的是原版加密镜像,如果您用别的镜像就不用解密这一步. 我在这里先列一些必须工具. 1.windows 10的esd镜像,或者iso镜像,可以参考这里的. h

一步一步搭建客服系统 (7) 多人共享的电子白板、画板

多人共享.同时操作的电子白板,让不同的参入者以不同的颜色来画画:可以保存当前room的内容,以让后来者可以直接加载所有内容. 在github上找到一个用html5 canvas实现的一个电子白板的例子: https://github.com/kblcuk/canvas-whiteboard 它是基于socket.io来实现多人白板的共享.操作.本文在它的基础上加上了房间,这样只有同一房间的人才会共享. 1  加入房间 客户端: var roomName = location.search.spl