Android-Animation (advanced tutorial for creating user-friendly animations) and androidanimation

Source: Internet
Author: User

Android-Animation (advanced tutorial for creating user-friendly animations) and androidanimation

Commonly used animations in android include Animation and Animator;

--- The 1st commonly used methods are used in Activity switching. for example, open an Activity. the effect of Sliding between the left and right is preferred for closing an Activity (as for how to configure the Tween animation in xml, it is everywhere on the Internet)

1. Start Activity

        private void gotoRegistActivity() {Intent intent=new Intent();intent.setClass(getActivity(),RegistActivity.class);startActivity(intent);getActivity().overridePendingTransition(R.anim.slide_right_in,R.anim.slide_left_out);}

2. Close the Activity (here, my project creates an Activity base class to implement code in the base class)

        @Overridepublic boolean onKeyDown(int keycCode, KeyEvent keyEvent) {if (keycCode==KeyEvent.KEYCODE_BACK) {this.finish();overridePendingTransition(R.anim.slide_left_in,R.anim.slide_right_out);return true;}return super.onKeyDown(keycCode, keyEvent);}

--- Animator Configuration

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android">    <objectAnimator        android:interpolator="@android:interpolator/decelerate_quint"        android:valueFrom="200dp" android:valueTo="0dp"        android:valueType="floatType"        android:propertyName="translationX"        android:duration="500" />    <objectAnimator        android:interpolator="@android:interpolator/decelerate_quint"        android:valueFrom="0.0" android:valueTo="1.0"        android:valueType="floatType"        android:propertyName="alpha"        android:duration="500" /></set>

2. Generally, Animator is configured on a new API, such as the Fragment that we are familiar with. I searched for it online, saying "add" and "remove". It is called before. After testing, after the FragmentTransaction starts the transaction

Call: (the following code is effective before detach () is called. The slide xml can be slightly changed based on the above Code. If you want to view the time, you are advised to add the animation time observation ):

mTransaction.setCustomAnimations(R.anim.slide_frag_in,R.anim.slide_frag_out);






Android: animation Problems

You can use property animation to adjust translationX or translationY to move the file.

Android Animation

There is a method, but it is not a good dismissal plan. I tried. If setFillAfter (true) is not set, the control is moved to the animation end position in the animation end listener. However, it has a jitter Bug.

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.