当前位置: 移动技术网 > IT编程>移动开发>Android > Activit跳转动画之界面上某个位置并裂开上下拉伸动画跳转

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

2019年07月24日  | 移动技术网IT编程  | 我要评论

闵紫英,绑恋 父子,我家的天使演员表

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

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

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

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

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

这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述

整体的效果就如上图,1,点击扫码 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是你需要截图的view
view 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, 0, 25, 320, 455);
bitmap b = bitmap.createbitmap(b1, 0, statusbarheight, width, height
- statusbarheight);
view.destroydrawingcache();
return b;
}
// 保存到sdcard
private 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)
@override
public 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, 0, 0, topfragment.bitmap.getwidth(), this.middata);
//且第二个图
bitmapbottom = bitmap.createbitmap(topfragment.bitmap, 0, this.middata, topfragment.bitmap.getwidth(), topfragment.bitmap.getheight() - middata);
}

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

<最外层有一个相对布局,这里就不写了只写一个播放动画的布局>
<linearlayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<linearlayout
android:id="@+id/id_linear_capture_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<imageview
android:id="@+id/loading_iv_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</linearlayout>
<linearlayout
android:id="@+id/id_linear_capture_under"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<imageview
android: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)
@override
public void ongloballayout() {
//设置了图片所以在这里获取他们两个的高,就是执行动画的距离
topheight = loading_iv_top.getheight(); //id_linear_capture_top id_linear_capture_under
bottonheight = loading_iv_bottm.getheight();
objectanimator animator = objectanimator.offloat(id_linear_capture_top, "translationy", 0, -topheight);
objectanimator animator1 = objectanimator.offloat(id_linear_capture_under, "translationy", 0, 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,在执行动画(这里只写打开的动画关闭的同理也就是一个动画而已)

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网