android - Vertical Screen Split Transitions (Animation) -


the animation should following:

  1. vertically split screen 2 parts.
  2. upper part moving upward.
  3. lower part moving down.
  4. finally, reverse way. (closing screen)

enter image description here

the idea simple:

  1. save activity bitmap
  2. split bitmap 2 parts
  3. 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

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -