Android炫酷广东快乐十分搭建的播放效果

使用广东快乐十分搭建述 dsluntan.com 贝塞尔曲线实现滑动效果,在使用属性动画实现水波纹效果,然后就能实现以上效果

三、实现

1、先封装动画框架,创建动画基础类

PathPoint.java

public class PathPoint {

public static final int MOVE = 0;
public static final int LINE = 1;
public static final int CURVE = 2;
float mControl0X, mControl0Y;
float mControl1X, mControl1Y;
public float mX, mY;
int mOperation;

//line/move
private PathPoint(int operation, float x, float y) {
    this.mOperation = operation;
    this.mX = x;
    this.mY = y;
}

//curve
private PathPoint(float c0X, float c0Y, float c1X, float c1Y, float x, float y) {
    this.mControl0X = c0X;
    this.mControl0Y = c0Y;
    this.mControl1X = c1X;
    this.mControl1Y = c1Y;
    this.mX = x;
    this.mY = y;
    this.mOperation = CURVE;

}

public static PathPoint moveTo(float x, float y) {

    return new PathPoint(MOVE, x, y);

}

public static PathPoint lineTo(float x, float y) {

    return new PathPoint(LINE, x, y);

}

public static PathPoint curveTo(float c0X, float c0Y, float c1X, float c1Y, float x, float y) {

    return new PathPoint(c0X, c0Y, c1X, c1Y, x, y);

}

}
创建动画集合类,并且保存绘制轨迹

AnimatorPath
public class AnimatorPath {
//记录轨迹
private List<PathPoint> mPoints = new ArrayList<>();

public void moveTo(float x, float y) {
    mPoints.add(PathPoint.moveTo(x, y));
}

public void lineTo(float x, float y) {
    mPoints.add(PathPoint.lineTo(x, y));
}

public void curveTo(float c0X, float c0Y, float c1X, float c1Y, float x, float y) {
    mPoints.add(PathPoint.curveTo(c0X, c0Y, c1X, c1Y, x, y));
}

public Collection<PathPoint> getPoints() {
    return mPoints;
}

}
3、实现页面布局

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

<ImageView
    android:id="@+id/album_cover"
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:background="#22eeff" />

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="120dp"
    android:layout_below="@id/album_cover"
    android:layout_marginTop="-15dp"
    android:background="@color/colorPrimary"
    android:elevation="4dp"
    android:minHeight="?attr/actionBarSize"
    android:paddingLeft="72dp">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fontFamily="sans-serif"
            android:text="大海大海"
            android:textColor="#FFF"
            android:textSize="30sp" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:fontFamily="sans-serif-light"
            android:text="王小二"
            android:textColor="#9cffffff"
            android:textSize="18sp" />
    </LinearLayout>
</android.support.v7.widget.Toolbar>

<FrameLayout
    android:id="@+id/fab_container"
    android:layout_width="match_parent"
    android:layout_height="128dp"
    android:layout_below="@id/album_cover"
    android:layout_marginTop="-30dp"
    android:elevation="10dp">

    <LinearLayout
        android:id="@+id/media_controls_container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:scaleX="0"
            android:scaleY="0"
            android:src="@mipmap/play" />

        <ImageView
            android:id="@+id/iv_pause_play"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_marginLeft="50dp"
            android:layout_marginRight="50dp"
            android:scaleX="0"
            android:scaleY="0"
            android:src="@mipmap/play" />

        <ImageView
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_marginRight="50dp"
            android:scaleX="0"
            android:scaleY="0"
            android:src="@mipmap/play" />

    </LinearLayout>

    <ImageButton
        android:id="@+id/fab"
        android:layout_width="56dp"
        android:layout_height="56dp"
        android:layout_gravity="top|right"
        android:layout_marginRight="72dp"
        android:background="@drawable/ripple"
        android:elevation="5dp"
        android:onClick="onPabPressed"
        android:transitionName="button_fab" />
</FrameLayout>

</RelativeLayout>
4、获取控件,并且设置点击事件,设置一些动画常量

private View mFab;
private FrameLayout mFabcontainer;
private LinearLayout mControlsContainer;

//从什么时候开始执行动画
private static final float SCALE_FACTOR = 13f;
//持续时间
private static final long ANIMATION_DURATION = 300;
//贝塞尔曲线滑动到什么时候开始执行动画
private static final float MINIMUN_X_DISTANCE = 200;
private boolean mRevealFlag;
private float mFabSize;

5,给mFab设置点击事件

private void onFabPressed(View view) {
final float startX = mFab.getX();
//开始动画
AnimatorPath path = new AnimatorPath();
path.moveTo(0, 0);
path.curveTo(-200, 200, -400, 100, -600, 50);
// path.lineTo(-600,50);

    ObjectAnimator anim = ObjectAnimator.ofObject(this, "fabLoc",
            new PathEvaluator(), path.getPoints().toArray());
    anim.setInterpolator(new AccelerateInterpolator());

// anim.setRepeatCount(ValueAnimator.INFINITE);
// anim.setRepeatMode(ValueAnimator.REVERSE);
anim.setDuration(ANIMATION_DURATION);
anim.start();
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {br/>@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
//到了path路径中的某个位置就是开始扩散动画
if (Math.abs(startX - mFab.getX()) > MINIMUN_X_DISTANCE) {
if (!mRevealFlag) {
ImageButton fab = (ImageButton) mFab;
fab.setImageDrawable(new BitmapDrawable());
//看布局里边的FabContainer要比toolbar背景高mFabSize/2(为了最初的半个fab效果)
mFabcontainer.setY(mFabcontainer.getY() + mFabSize / 2);
//fab放大动画
mFab.animate()
.scaleXBy(SCALE_FACTOR)
.scaleYBy(SCALE_FACTOR)
.setListener(mEndRevealListener)
.setDuration(ANIMATION_DURATION);
mRevealFlag = true;
}
}
}
});
}

public void setFabLoc(PathPoint newLoc) {
    mFab.setTranslationX(newLoc.mX);
    if (mRevealFlag) {
        //因为布局里边的mFabcontainer要比toolbar背景高mFabSize/2,所以fab为了看起来平顺,需要上移mFabSize/2
        mFab.setTranslationY(newLoc.mY - (mFabSize / 2));
    } else {
        mFab.setTranslationY(newLoc.mY);
    }

}

private AnimatorListenerAdapter mEndRevealListener = new AnimatorListenerAdapter() {
    @Override
    public void onAnimationEnd(Animator animation) {
        super.onAnimationEnd(animation);
        mFab.setVisibility(View.INVISIBLE);
        mFabcontainer.setBackgroundColor(getResources().getColor(R.color.colorAccent));
        //reveal动画完毕后,接着每一个子控件都有个缩放动画(依次顺序出来)
        for (int i = 0; i < mControlsContainer.getChildCount(); i++) {
            View v = mControlsContainer.getChildAt(i);
            ViewPropertyAnimator animate = v.animate()
                    .scaleX(1)
                    .scaleY(1)
                    .setDuration(ANIMATION_DURATION);
            animate.setStartDelay(i * 50);
            animate.start();
        }
    }
};

PathEvaluator
public class PathEvaluator implements TypeEvaluator<PathPoint> {br/>@Override
public PathPoint evaluate(float t, PathPoint startValue, PathPoint endValue) {
//t执行的百分比 (0~1)
float x, y;
if (endValue.mOperation == PathPoint.CURVE) {
//三阶贝塞尔曲线 公式
float oneMinusT = 1 - t;
x = oneMinusT oneMinusT oneMinusT startValue.mX +
3
oneMinusT oneMinusT t endValue.mControl0X +
3
oneMinusT t t endValue.mControl1X +
t
t t endValue.mX;
y = oneMinusT oneMinusT oneMinusT startValue.mY +
3
oneMinusT oneMinusT t endValue.mControl0Y +
3
oneMinusT t t endValue.mControl1X +
t
t t endValue.mY;
} else if (endValue.mOperation == PathPoint.LINE) {
//x=起始点+t起始点和终点的距离
x = startValue.mX + t
(endValue.mX - startValue.mX);
y = startValue.mY + t * (endValue.mY - startValue.mY);
} else {
x = endValue.mX;
y = endValue.mY;

    }
    return PathPoint.moveTo(x, y);
}

}
注意:属性动画既可以改变属性,也可以改变一个变量或者方法

Android炫酷广东快乐十分搭建的播放效果

原文地址:http://blog.51cto.com/13928036/2161294

时间: 2024-08-24 11:39:09

Android炫酷广东快乐十分搭建的播放效果的相关文章

android炫酷动画源码,QQ菜单、瀑布流、二维码源码

Android精选源码 自定义弹框封装,ProgressDialog,StatusDialog和Toast,支持自定义颜色 有深度感的fragment代码 在屏幕顶部或者底部显示提示 短信转发工具,自动转发短信到手机或邮箱 美观的菜单隐藏在主界面底部的抽屉导航. 仿QQ菜单.瀑布流.数据库.二维码生成 andorid实现"划词翻译"功能的项目 android界面切换的效果,输入文字时背景图缩放效果 android一款很炫的动画代码 Android雷达扫描图,超高仿QQ附近的人 Andr

「珍藏」老司机为你推荐10个炫酷的开源库,看完的人都收藏了

前言 技术群里面经常有人问到一些炫酷的UI效果实现方法,有时候我都是给一个相同或者相似效果的Github链接,有同学私信给我说,大佬,怎么这些效果你都能找到?你是怎么搜索的,或者有其他什么秘方?会利用Google.百度等搜索工具搜索是一方面,另一个重要的方面是:记录搜藏,当看到一个炫酷的效果的时候,记得收藏起来,记录到自己云笔记或者收藏夹里,看得多了,印象就比较深刻,当遇到类似效果的时候,到自己记录收藏的地方找就是了.今天为大家推荐我所收藏的一些炫酷实用的效果的开源库(选择其中10个). 1.D

HTML5 canvas炫酷棱镜效果的幻灯片特效

这是一款效果非常炫酷华丽的HTML5 canvas带棱镜效果的幻灯片特效.这个特效在每一个幻灯片的前面放置一个图形,并将图形制作为三棱镜效果,它底下的幻灯片图片会被"折射"到棱镜上面,形成一种棱镜折射效果. 所有的现代浏览器都支持这个幻灯片特效,包括IE9. 效果演示:http://www.htmleaf.com/Demo/201504011607.html 下载地址:http://www.htmleaf.com/html5/html5-canvas/201504011606.html

canvas - 炫酷的3D星空

1.国际惯例,先上效果 (⊙o⊙)- 效果图看上去效果并不很炫酷啊,直接戳 这里 看效果吧! 2代码部分 html: <canvas id="canvas" width="1920" height="1080"></canvas> css: *{margin: 0;padding: 0;} /*没啥必须的css*/ js:(这个博主也是够了,那么多的js代码,一点注释都没有,差评!)公子莫慌,由于代码比较多,注释部分就不在

Android基础控件——ImageView的自定义,巧用Matrix实现图片不变形的炫酷PK条

前言 在开发中常常会遇到PK条制作,如果在PK条中是纯色的情况下,比较好办,如下:我们通常会设置其权重进行更新两个PK条的进度,实现起来也简单 //更新PkBar宽度比例 private void updateLayoutParams(float ratio) { LinearLayout.LayoutParams paramsLeft = (LinearLayout.LayoutParams) mLeftBar.getLayoutParams(); LinearLayout.LayoutPar

开源分享三(炫酷的Android Loading动画)

开源分享三(炫酷的Android Loading动画) 分享GitHub上的一些Loading,为了提升产品用户体验,一个好的Loading必然是不可缺少的,对于一些耗时需要用户等待的页面来说会转移用户注意力,不会显得那么烦躁,所以你可以看到市面上一些App中的各种各样的Loading动画,从这些实现思路上可以打开你们自己的思维,没准也会有创新的Loading动画出现. android-shapeLoadingView 新版58同城加载页面动画. CircleProgress 一个效果很酷炫很创

Android 自定义控件玩转字体变色 打造炫酷ViewPager指示器

Android 自定义控件玩转字体变色 打造炫酷ViewPager指示器

Android实现炫酷SVG动画效果

svg是目前十分流行的图像文件格式了,svg严格来说应该是一种开放标准的矢量图形语言,使用svg格式我们可以直接用代码来描绘图像,可以用任何文字处理工具打开svg图像,通过改变部分代码来使图像具有交互功能,并可以随时插入到HTML中通过浏览器(如火狐浏览器)来观看.使用svg格式可让你设计激动人心的.高分辨率的Web图形页面. svg格式具备目前网络流行的jpg和png等格式无法具备的优势:可以任意放大图形显示,但绝不会以牺牲图像质量为代价;可在svg图像中保留可编辑和可搜寻的状态;平均来讲,s

Android 教你打造炫酷的ViewPagerIndicator 不仅仅是高仿MIUI

1.概述 哈,今天给大家带来一个ViewPagerIndicator的制作,相信大家在做tabIndicator的时候,大多数人都用过 TabPageIndicator,并且很多知名APP都使用过这个开源的指示器.大家有没有想过如何自己去实现这样的一个指示器,并且代码会有多复杂 呢~~~今天,我就带领大家来从无到有的实现这样一个指示器,当然了,不准备一模一样,搞得没有创新似的,再看标题,跟MIUI相关,所以我们准备做一个 特性与TabPageIndicator一致的,但是样子和MIUI的Tab一