Activit跳转动画之界面上某个位置并裂开上下拉伸动画跳转

Activit跳转动画之界面上某个位置并裂开上下拉伸动画跳转,第1张

概述需求:Activity(fragment)跳转的时候当前界面裂开,上下各自拉出手机屏幕,之后跳转到相对应的Activity.整体效果图如下

需求:Activity(fragment)跳转的时候当前界面裂开,上下各自拉出手机屏幕,之后跳转到相对应的Activity.整体效果图如下

思路:1,在当前Activity中截取当前手机的屏幕获取到bitmap,然后根据具体位置(比如这里是扫码图标中间裂开)计算获取到,中间裂开距离手机上和下的距离,在传递给跳转后的Activity

(跳转前的Activity做两件事情,1,截取屏幕获取bitmap2,计算出具体裂开位置距离屏幕上下的距离,传递给第二个activity方便来切割真个截图)

2,跳转后的Activity执行动画即可

(,(我上面分析的没有带上我截图中自带两个vIEw风别跟着上下图已启动的如果需要的话可以私密我))




整体的效果就如上图,点击扫码 2,中间裂开执行上线拉伸动画,(这个时候是可以看见需要跳转的Activity的)3,动画结束

具体实现

一:跳转前activity的截屏获取bitmap,并且获取到裂开位置的数值,传递给第二个activity,方便之后的切割

//这个bitmap我是用public static Bitmap bitmap;接受的方便第二个activity直接获取bitmap = ScreenShot.takeScreenShot(getActivity());

**//这个是工具类直接调用就可以获取到手机屏幕了

package com.lzyc.ybtappcal.util;import androID.app.Activity;import androID.graphics.Bitmap;import androID.graphics.Rect;import androID.vIEw.VIEw;import com.lzyc.ybtappcal.activity.LoaddingSleepActivity;import java.io.fileNotFoundException;import java.io.fileOutputStream;import java.io.IOException;import java.util.ArrayList;import java.util.List;/*** Created by lovelin on 2016/7/20.*/public class ScreenShot {private static int mHIDdenVIEwMeasureHeight; //中间切割的高度private static int screenHeightPixels; //屏幕高度// 获取指定Activity的截屏,保存到png文件public static Bitmap takeScreenShot(Activity activity) {// VIEw是你需要截图的VIEwVIEw vIEw = activity.getwindow().getDecorVIEw();vIEw.setDrawingCacheEnabled(true);vIEw.buildDrawingCache();Bitmap b1 = vIEw.getDrawingCache();// 获取状态栏高度Rect frame = new Rect();activity.getwindow().getDecorVIEw().getwindowVisibledisplayFrame(frame);int statusbarHeight = frame.top;LogUtil.e("TAG","" + statusbarHeight);// 获取屏幕长和高int wIDth = activity.getwindowManager().getDefaultdisplay().getWIDth();int height = activity.getwindowManager().getDefaultdisplay().getHeight();// 去掉标题栏// Bitmap b = Bitmap.createBitmap(b1,25,320,455);Bitmap b = Bitmap.createBitmap(b1,statusbarHeight,wIDth,height- statusbarHeight);vIEw.destroyDrawingCache();return b;}// 保存到sdcardprivate static voID savePic(Bitmap b,String strfilename) {fileOutputStream fos = null;try {fos = new fileOutputStream(strfilename);if (null != fos) {b.compress(Bitmap.CompressFormat.PNG,90,fos);fos.flush();fos.close();}} catch (fileNotFoundException e) {e.printstacktrace();} catch (IOException e) {e.printstacktrace();}}// 程序入口public static voID shoot(Activity a) {// ScreenShot.savePic(ScreenShot.takeScreenShot(a),"sdcard/xx.png");}}

1,获取当前扫描按钮中间的距离,

private voID getMessureHeight() {v.ID_linea_top.getVIEwTreeObserver().addOnGlobalLayoutListener(new VIEwTreeObserver.OnGlobalLayoutListener() {@TargetAPI(Build.VERSION_CODES.JELLY_BEAN)@OverrIDepublic voID onGlobalLayout() {int imageHanlfheight = (v.iv_fg_top.getBottom() - v.iv_fg_top.gettop()) / 2; //image 的一半高度int bottom = v.iv_fg_top.getBottom();/***imagevIEw扫描按钮底部距离 - 按钮本身一半的距离 = 距离手机顶部的距离(就是播放动画需要截取的上半图片的高度)*/mIDData = bottom - imageHanlfheight;v.ID_linea_top.getVIEwTreeObserver().removeOnGlobalLayoutListener(this);}});}

2,*紧接着界面跳转传递参数mIDData 即可

Bundle mBundle = new Bundle();mBundle.putInt(Contants.KEY_PAGE_SEARCH,Contants.VAL_PAGE_SEARCH_top);mBundle.putInt("mIDData",mIDData);mBundle.putInt("h",h);mBundle.putInt("topSplitHeight",topSplitHeight);openActivityNoAnim(CaptureActivity.class,mBundle);

3,*跳转取消系统动画

public voID openActivityNoAnim(Class<? extends Activity> ActivityClass,Bundle b) {Intent intent = new Intent(mContext,ActivityClass);intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);intent.putExtras(b);startActivity(intent);}

二:代码截取上一个activity(fragment)的bitmap分成两个执行动画的bitmap

private voID cutting() {// 切割第一个图bitmaptop = Bitmap.createBitmap(topFragment.bitmap,topFragment.bitmap.getWIDth(),this.mIDData);//且第二个图bitmapBottom = Bitmap.createBitmap(topFragment.bitmap,this.mIDData,topFragment.bitmap.getHeight() - mIDData);}

1,在第二个Activity最外层先一个相对布局盖在上面用来执行动画我闲的布局如下(这里我只贴出在外层的布局,里面需要显示的布局就不写了)

<最外层有一个相对布局,这里就不写了只写一个播放动画的布局><linearLayoutandroID:layout_wIDth="match_parent"androID:layout_height="match_parent"androID:orIEntation="vertical"><linearLayoutandroID:ID="@+ID/ID_linear_capture_top"androID:layout_wIDth="match_parent"androID:layout_height="wrap_content"androID:orIEntation="vertical"><ImageVIEwandroID:ID="@+ID/loading_iv_top"androID:layout_wIDth="wrap_content"androID:layout_height="wrap_content" /></linearLayout><linearLayoutandroID:ID="@+ID/ID_linear_capture_under"androID:layout_wIDth="match_parent"androID:layout_height="match_parent"androID:orIEntation="vertical"><ImageVIEwandroID:ID="@+ID/loading_iv_bottm"androID:layout_wIDth="wrap_content"androID:layout_height="wrap_content" /></linearLayout></linearLayout>

2,找到vIEw,设置他们上下需要执行动画的bitmap

/*** 播放动画*/private voID startAnima() {cutting();final ImageVIEw loading_iv_top = (ImageVIEw) findVIEwByID(R.ID.loading_iv_top);final ImageVIEw loading_iv_bottm = (ImageVIEw) findVIEwByID(R.ID.loading_iv_bottm);ID_linear_capture_top = (linearLayout) findVIEwByID(R.ID.ID_linear_capture_top);ID_linear_capture_under = (linearLayout) findVIEwByID(R.ID.ID_linear_capture_under);final relativeLayout ID_relative_capture = (relativeLayout) findVIEwByID(R.ID.ID_relative_capture);//设置上下播放拉伸图片loading_iv_top.setimageBitmap(this.bitmaptop);loading_iv_bottm.setimageBitmap(this.bitmapBottom);ID_relative_capture.getVIEwTreeObserver().addOnGlobalLayoutListener(new VIEwTreeObserver.OnGlobalLayoutListener() {@TargetAPI(Build.VERSION_CODES.JELLY_BEAN)@OverrIDepublic voID onGlobalLayout() {//设置了图片所以在这里获取他们两个的高,就是执行动画的距离topHeight = loading_iv_top.getHeight(); //ID_linear_capture_top ID_linear_capture_underbottonHeight = loading_iv_bottm.getHeight();ObjectAnimator animator = ObjectAnimator.offloat(ID_linear_capture_top,"translationY",-topHeight);ObjectAnimator animator1 = ObjectAnimator.offloat(ID_linear_capture_under,bottonHeight);AnimatorSet animset = new AnimatorSet();animset.play(animator).with(animator1);animset.setDuration(400);animset.start();ID_relative_capture.getVIEwTreeObserver().removeOnGlobalLayoutListener(this);}});}

3,到此动画打开 *** 作完毕,(我上面分析的没有带上我截图中自带两个vIEw风别跟着上下图已启动的如果需要的话可以私密我)

最后总结:1,当前截屏获取bitmap2,第二个activity剪切上线需要执行动画的bitma3,在执行动画(这里只写打开的动画关闭的同理也就是一个动画而已)

总结

以上是内存溢出为你收集整理的Activit跳转动画之界面上某个位置并裂开上下拉伸动画跳转全部内容,希望文章能够帮你解决Activit跳转动画之界面上某个位置并裂开上下拉伸动画跳转所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1148760.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存