Activit a position on the interface of the drawing and splits up and down stretch the animation jump _android

Source: Internet
Author: User

Requirements: Activity (fragment) jump when the current interface split, up and down each pull out the phone screen, and then jump to the corresponding activity. The overall effect is shown below

Train of thought: 1, in the current activity to intercept the current mobile phone screen to get to bitmap, and then based on the specific location (such as the Sweep code icon in the middle of the split) calculated to obtain, the middle split distance between the phone and the lower distance, in the transfer to the activity after the jump

(Jump before the activity to do two things, 1, intercept screen to obtain BITMAP2, calculate the specific split position distance from the screen up and down, passed to the second event to facilitate the cutting of the entire screenshot)

2, the activity after the jump to perform animation can be

(What I analyzed above didn't take my screenshot with me with two view wind don't follow the up and down map has been started if you need to be able to private me))




The overall effect is as above, 1, click Sweep Code 2, split in the middle to perform the online stretching animation, (this time is to see the activity to jump) 3, the end of the animation

Concrete implementation

First: Jump before the activity of the screen to obtain bitmap, and obtain the value of the split position, passed to the second activity, convenient after the cutting

This Bitmap I am using public static Bitmap Bitmap; Easy to receive
Bitmap = Screenshot.takescreenshot (getactivity ()) for the second activity ;

**//This is the tool class direct call can get to the phone screen

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;//Intermediate cut height private static int screenheightpixels; Screen height//Get screenshots of specified activity, save to PNG file public static Bitmap Takescreenshot (activity activity) {//view is the view view you need to capture
= Activity.getwindow (). Getdecorview ();
View.setdrawingcacheenabled (TRUE);
View.builddrawingcache ();
Bitmap B1 = View.getdrawingcache ();
Gets the status bar height Rect frame = new Rect ();
Activity.getwindow (). Getdecorview (). Getwindowvisibledisplayframe (frame);
int statusbarheight = Frame.top;
LOGUTIL.E ("TAG", "" + statusbarheight); Get screen length and high int width = Activity.getwindoWmanager (). Getdefaultdisplay (). GetWidth ();
int height = Activity.getwindowmanager (). Getdefaultdisplay (). GetHeight ();
Remove title bar//Bitmap B = Bitmap.createbitmap (B1, 0, 25, 320, 455);
Bitmap B = Bitmap.createbitmap (b1, 0, Statusbarheight, width, height-statusbarheight);
View.destroydrawingcache ();
return b; }//Save to SDcard private static void Savepic (Bitmap B, String strFileName) {FileOutputStream fos = null; try {fos = new Fi
Leoutputstream (strFileName); if (null!= fos) {b.compress (Bitmap.CompressFormat.PNG, N, Fos); Fos.flush (); Fos.close ();}}
catch (FileNotFoundException e) {e.printstacktrace ();} catch (IOException e) {e.printstacktrace ();}} Program entry public static void shoot (activity a) {//Screenshot.savepic (Screenshot.takescreenshot (a), "sdcard/xx.png");}

1, get the distance between the current scan button,

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; The half height of image is
int bottom = V.iv_fg_top.getbottom ();
/**
*imageview Scan button Bottom distance-half the distance of the button itself = distance from the top of the phone (that is, the height of the upper half of the picture to play the animation)
* * * *
middata = bottom- Imagehanlfheight;
V.id_linea_top.getviewtreeobserver (). Removeongloballayoutlistener (this);
}
);

2,* immediately after the interface jump transfer parameters Middata can

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,* Jump Cancel System animation

public void Openactivitynoanim (class<? extends activity> Activityclass, Bundle b) {
Intent Intent = new Intent (m context, activityclass);
Intent.setflags (intent.flag_activity_no_animation);
Intent.putextras (b);
StartActivity (intent);
}

Second: The code intercepts the bitmap of the previous activity (fragment) into two animated bitmap

private void Cutting () {
//Cut first figure
bitmaptop = Bitmap.createbitmap (topfragment.bitmap, 0, 0, TopFragment.bitmap.getWidth (), this.middata);
And the second figure
Bitmapbottom = Bitmap.createbitmap (topfragment.bitmap, 0, This.middata, TopFragment.bitmap.getWidth (), TopFragment.bitmap.getHeight ()-middata);

1, at the outermost part of the second activity. First, a relative layout is used to perform the animation. My free layout is as follows (here I only post the layout of the outer layer, the layout that needs to be displayed will not be written)

< The outermost layer has a relative layout, there is no write only a play animation layout >
<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, find the view, set them up and down need to perform animation bitmap

/** * Play animation/private void Startanima () {cutting (); final ImageView loading_iv_top = (imageview) Findviewbyid (R.id.loadi
Ng_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);
Set up and down play the stretch picture 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 () {//Set the picture so get them both high, that's the distance to perform the animation 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, to this animation to open the operation completed, (I did not bring up the analysis above with my screenshot with two view wind do not follow the up and down map has been started if necessary, you can private me)

Finally summary: 1, the current screenshot to get BITMAP2, the second activity cut on the line needs to perform an animated bitma3, in the animation (here only write open animation off of the same is just an animation)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.