仿Boss直聘-查看头像

简介: 发现Boss直聘app做的还是,比较不错的吧。。先看效果,致谢 Image-ZoomerGIF.gif怎么用?@Overridepublic void onClick(View v) {super.

发现Boss直聘app做的还是,比较不错的吧。。先看效果,致谢 Image-Zoomer

GIF.gif

怎么用?

<pre>

@Override
public void onClick(View v) {
super.onClick(v);
if (R.id.tv == v.getId()) {
startActivity(ZoomActivity.class);
} else if (R.id.iv == v.getId()) {
new BossZoomHelper(this, imageView, 400);
}
}
</pre>

原理很简单,

<pre>
package org.alex.bosszoomanim;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.Rect;
import android.support.v7.widget.ContentFrameLayout;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import android.widget.FrameLayout;
import android.widget.ImageView;

import org.alex.util.LogUtil;

/**
* 作者:Alex
* 时间:2016/10/8 12:48
* 简述:
*/
public class BossZoomHelper {
private Animator animator;
private ImageView copyImageView;

public BossZoomHelper(final Activity activity, final View originalView) {
    this(activity, originalView, 400);
}

public BossZoomHelper(final Activity activity, final View originalView, final long duration) {
    if (animator != null) {
        animator.cancel();
    }
    final ContentFrameLayout container = (ContentFrameLayout) activity.findViewById(android.R.id.content);
    copyImageView = new ImageView(activity);
    int matchParent = FrameLayout.LayoutParams.MATCH_PARENT;
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(matchParent, matchParent);
    copyImageView.setLayoutParams(params);
    if (originalView instanceof ImageView) {
        copyImageView.setImageDrawable(((ImageView) originalView).getDrawable());
    } else {
        Bitmap bm = view2Bitmap(originalView);
        if (bm != null) {
            copyImageView.setImageBitmap(bm);
        }
    }
    copyImageView.setVisibility(View.GONE);
    container.addView(copyImageView);
    final Rect startRect = new Rect();
    final Rect endRect = new Rect();
    Point offsetPoint = new Point();
    originalView.getGlobalVisibleRect(startRect);
    /\*\*
     \* r 是 绝对(global)坐标参数,包含状态栏、ActionBar、底部虚拟键
     \* globalOffset 用于将global坐标转换成local坐标,这里的local坐标,是相对于内容区的坐标,也就是除了状态栏和action bar和虚拟按键的区域。
     \* \*/
    container.getGlobalVisibleRect(endRect, offsetPoint);
    startRect.offset(-offsetPoint.x, -offsetPoint.y);
    endRect.offset(-offsetPoint.x, -offsetPoint.y);
    final float startScale;
    float scaleSize;
    float startScaleFinal;
    LogUtil.e("-offsetPoint.x = " + (-offsetPoint.x) + " -offsetPoint.y = " + (-offsetPoint.y));
    LogUtil.e("startRect.width()  = " + startRect.width() + " startRect.height() = " + startRect.height());
    LogUtil.e("endRect.width()  = " + endRect.width() + " endRect.height() = " + endRect.height());

    if ((float) endRect.width() / (float) endRect.height() > (float) startRect.width() / (float) startRect.height()) {
        startScale = (float) startRect.height() / (float) endRect.height();
        scaleSize = startScale \* (float) endRect.width();
        startScaleFinal = (scaleSize - (float) startRect.width()) / 2.0F;
        startRect.left = (int) ((float) startRect.left - startScaleFinal);
        startRect.right = (int) ((float) startRect.right + startScaleFinal);
    } else {
        startScale = (float) startRect.width() / (float) endRect.width();
        scaleSize = startScale \* (float) endRect.height();
        startScaleFinal = (scaleSize - (float) startRect.height()) / 2.0F;
        startRect.top = (int) ((float) startRect.top - startScaleFinal);
        startRect.bottom = (int) ((float) startRect.bottom + startScaleFinal);
    }
    copyImageView.setPivotX(0.0F);
    copyImageView.setPivotY(0.0F);

    AnimatorSet showAnimatorSet = new AnimatorSet();
    showAnimatorSet.setDuration(duration);
    showAnimatorSet.play(ObjectAnimator.ofFloat(copyImageView, View.X, new float[]{(float) startRect.left, (float) endRect.left}))
            .with(ObjectAnimator.ofFloat(copyImageView, View.Y, new float[]{(float) startRect.top, (float) endRect.top}))
            .with(ObjectAnimator.ofFloat(copyImageView, View.SCALE_X, new float[]{startScale, 1.0F}))
            .with(ObjectAnimator.ofFloat(copyImageView, View.SCALE_Y, new float[]{startScale, 1.0F}));
    showAnimatorSet.setInterpolator(new DecelerateInterpolator());
    showAnimatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            copyImageView.setVisibility(View.VISIBLE);

        }

        public void onAnimationEnd(Animator animation) {
            animator = null;
        }

        public void onAnimationCancel(Animator animation) {
            destroy(originalView, container);
        }
    });
    showAnimatorSet.start();

    animator = showAnimatorSet;
    copyImageView.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            if (animator != null) {
                animator.cancel();
            }
            copyImageView.setBackgroundColor(0);
            AnimatorSet hiddenAnimatorSet = new AnimatorSet();
            hiddenAnimatorSet.play(ObjectAnimator.ofFloat(copyImageView, View.X, new float[]{(float) startRect.left}))
                    .with(ObjectAnimator.ofFloat(copyImageView, View.Y, new float[]{(float) startRect.top}))
                    .with(ObjectAnimator.ofFloat(copyImageView, View.SCALE_X, new float[]{startScale}))
                    .with(ObjectAnimator.ofFloat(copyImageView, View.SCALE_Y, new float[]{startScale}));
            hiddenAnimatorSet.setInterpolator(new DecelerateInterpolator());
            hiddenAnimatorSet.setDuration(duration);
            hiddenAnimatorSet.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationStart(Animator animation) {
                    super.onAnimationStart(animation);
                }

                public void onAnimationEnd(Animator animation) {
                    if (animator != null) {
                        animator.cancel();
                    }
                    destroy(originalView, container);
                }

                public void onAnimationCancel(Animator animation) {
                    destroy(originalView, container);
                }
            });
            hiddenAnimatorSet.start();
            animator = hiddenAnimatorSet;
        }
    });
}

private void destroy(View originalView, ContentFrameLayout container) {
    originalView.setAlpha(1.0F);
    copyImageView.setVisibility(View.GONE);
    container.removeView(copyImageView);
    animator = null;
}

private Bitmap view2Bitmap(View view) {
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap bmp = view.getDrawingCache();
    if (bmp == null) {
        return null;
    }
    Bitmap bp;
    bp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight());
    view.destroyDrawingCache();
    return bp;
}

}

</pre>

https://github.com/Alex-Cin/BossAnim

目录
相关文章
|
5月前
|
前端开发 小程序 编译器
有意思,圣诞节自己做一个装饰圣诞帽头像的APP!
有意思,圣诞节自己做一个装饰圣诞帽头像的APP!
|
11月前
|
人工智能 Serverless 异构计算
【有奖体验】叮!你有一张 3D 卡通头像请查收
立即体验基于函数计算部署【图生图】一键部署 3D 卡通风格模型,秒生成属于自己的 3D 卡通图!
基于盲盒商城的飞机大战游戏
基于盲盒商城的飞机大战游戏
71 0
基于盲盒商城的飞机大战游戏
喜迎国庆,几行简单代码即可实现【国庆风格】社交头像
喜迎国庆,几行简单代码即可实现【国庆风格】社交头像
136 0
喜迎国庆,几行简单代码即可实现【国庆风格】社交头像
|
JSON 小程序 前端开发
【今天吃什么】微信小程序炫酷摇一摇来告诉你!
【今天吃什么】微信小程序炫酷摇一摇来告诉你!
1603 1
【今天吃什么】微信小程序炫酷摇一摇来告诉你!
|
定位技术 Python
元旦C位出道,用微信好友头像拼个中国地图吧!
准备用好友头像拼接成背景图,用中间透明的中国地图加以覆盖,即可生成一个酷炫的照片地图。
1363 0
元旦C位出道,用微信好友头像拼个中国地图吧!
|
缓存 Python
用Python拼字,实现微信好友头像生成祝福文字,做朋友圈最靓的仔
利用汉字库HZK16文件来实现,拿到点阵信息后,将背景图片当做16*16点阵,用头像图片和空白来替代点阵中的点。这里为了提高字笔画的丰富性,采用一个点对应4个图片。
457 0
用Python拼字,实现微信好友头像生成祝福文字,做朋友圈最靓的仔
|
大数据
BOSS说:数据领域首档人物专访类栏目
直播学习时间7月1日下午15:00-16:30,咱们不见不散~
BOSS说:数据领域首档人物专访类栏目
|
Web App开发 机器人 Windows
一个Boss直聘机器人, 自动回复发简历
goBoss 基佬github地址 这是基于go语言编写的一款boss直聘机器人软件(牛人版)。附上Python版本, 无需配置Go环境, 我会提供windows和macos的可执行程序。不喜勿喷O(∩_∩)O~ 闪光点 自动回复boss消息 回复消息有3种类型。
4179 0
类似微信图片浏览,常见应用场景如微信朋友圈照片九宫格和微信聊天图片预览
本项目受Google官方demo Zooming a View 启发,实现了点击小图放大至全屏预览,退出全屏恢复至原来位置这两个过程的动画过渡。 常见应用场景如微信朋友圈照片九宫格和微信聊天图片预览,某些手机系统相册等viewpager图片查看 缩放 拖拽下拉缩小退出(效果同微信图片浏览) 特点1.支持自定义图片加载框架。
2182 0