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: