android - Vertical Screen Split Transitions (Animation) -
the animation should following:
- vertically split screen 2 parts.
- upper part moving upward.
- lower part moving down.
- finally, reverse way. (closing screen)
the idea simple:
- save activity bitmap
- split bitmap 2 parts
- animate bitmaps outwards (up , down)
in order bitmap of activity:
view root = curractivity.getwindow().getdecorview().findviewbyid(android.r.id.content); root.setdrawingcacheenabled(true); bitmap bmp = root.getdrawingcache();
in order split bitmap:
int splitycoord = (splitycoord != -1 ? splitycoord : bmp.getheight() / 2); if (splitycoord > bmp.getheight()) throw new illegalargumentexception("split y coordinate [" + splitycoord + "] exceeds activity's height [" + bmp.getheight() + "]"); bitmap mbmp1 = bitmap.createbitmap(bmp, 0, 0, bmp.getwidth(), splitycoord); bitmap mbmp2 = bitmap.createbitmap(bmp, 0, splitycoord, bmp.getwidth(), bmp.getheight() - splitycoord); private static int[] mloc1; private static int[] mloc2; mloc1 = new int[]{0, root.gettop()}; mloc2 = new int[]{0, root.gettop() + splitycoord}; private static imageview mtopimage; private static imageview mbottomimage; mtopimage = createimageview(destactivity, mbmp1, mloc1); mbottomimage = createimageview(destactivity, mbmp2, mloc2); private static imageview createimageview(activity destactivity, bitmap bmp, int loc[]) { imageview imageview = new imageview(destactivity); imageview.setimagebitmap(bmp); windowmanager.layoutparams windowparams = new windowmanager.layoutparams(); windowparams.gravity = gravity.top; windowparams.x = loc[0]; windowparams.y = loc[1]; windowparams.height = viewgroup.layoutparams.wrap_content; windowparams.width = viewgroup.layoutparams.wrap_content; windowparams.flags = windowmanager.layoutparams.flag_layout_in_screen windowparams.format = pixelformat.translucent; windowparams.windowanimations = 0; destactivity.getwindowmanager().addview(imageview, windowparams); return imageview; }
after created bitmaps, apply animation
animatorset msetanim = new animatorset(); mtopimage.setlayertype(view.layer_type_hardware, null); mbottomimage.setlayertype(view.layer_type_hardware, null); msetanim.addlistener(new animator.animatorlistener() { @override public void onanimationend(animator animation) { clean(destactivity); } @override public void onanimationcancel(animator animation) { clean(destactivity); } ... }); animator anim1 = objectanimator.offloat(mtopimage, "translationy", mtopimage.getheight() * -1); animator anim2 = objectanimator.offloat(mbottomimage, "translationy", mbottomimage.getheight()); msetanim.setduration(duration); msetanim.playtogether(anim1, anim2); msetanim.start(); private void clean(activity activity) { if (mtopimage != null) { mtopimage.setlayertype(view.layer_type_none, null); try { activity.getwindowmanager().removeviewimmediate(mbottomimage); } catch (exception ignored) {} } if (mbottomimage != null) { mbottomimage.setlayertype(view.layer_type_none, null); try { activity.getwindowmanager().removeviewimmediate(mtopimage); } catch (exception ignored) {} } mbmp1 = null; mbmp2 = null; }
above code reference purpose. can find full demo below link.
ref link: activitysplitanimation
Comments
Post a Comment