Reality of the animation effect when the Android layout changes (2)

Source: Internet
Author: User

MainActivity is as follows:

Package wy. test; import android. animation. animatorInflater; import android. animation. layoutTransition; import android. animation. objectAnimator; import android. app. activity; import android. content. context; import android. OS. bundle; import android. view. view; import android. view. view. onClickListener; import android. widget. button; import android. widget. linearLayout; import android. widget. textView;/*** Demo Description: * reality of the animation effect when the layout changes (2) * an animation is displayed when the layout changes, so that the switching effect is not too stiff. * Similarly, you can also set animations at different time points for layout changes. There are four types: * LayoutTransition. APPEARING, LayoutTransition. CHANGE_APPEARING, * LayoutTransition. CHANGE_DISAPPEARING, LayoutTransition. DISAPPEARING *** references: * 1 http://blog.csdn.net/alrdy/article/details/7836963 * 2 http://www.cnblogs.com/mengdd/p/3305973.html * 3 http://blog.csdn.net/think_soft/article/details/12417107 ** Thank you very much */public class TestAnimateLayoutChangesActivity extends Activity {private LinearLayout mRootLinearLayout; private Context mContext; private TextView mTextView; @ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); init ();} private void init () {mContext = this; mRootLinearLayout = (LinearLayout) findViewById (R. id. rootLinearLayout); mTextView = (TextView) findViewById (R. id. textView); mTextView. setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View v) {Button addedButton = new Button (mContext); addedButton. setText ("Button"); // property animation ObjectAnimatorObjectAnimator objectAnimator = (ObjectAnimator) AnimatorInflater. loadAnimator (mContext, R. animator. scalexanimator); objectAnimator. setTarget (addedButton); LayoutTransition layoutTransition = new LayoutTransition (); // The layoutTransition is displayed when a new View is added. setAnimator (LayoutTransition. APPEARING, objectAnimator); // Add LayoutTransition mRootLinearLayout to the layout. setLayoutTransition (layoutTransition); mRootLinearLayout. addView (addedButton );}});}}

Main. xml is as follows:

 
     
  
 

Scalexanimator. xml is as follows:

 
 


Related Article

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.