Android transition(RelativeLayout动画实现)
//通过偏移各个开始时间来创建“stagger”动画的自定义过渡 mStaggeredTransition = new TransitionSet(); Transition first = new ChangeBounds(); Transition second = new ChangeBounds(); Transition third = new ChangeBounds(); Transition fourth = new ChangeBounds(); first.addTarget(mFirstButton); second.setStartDelay(50).addTarget(mSecondButton); third.setStartDelay(100).addTarget(mThirdButton); fourth.setStartDelay(150).addTarget(mFourthButton); mStaggeredTransition.addTransition(first).addTransition(second).addTransition(third). addTransition(fourth); } private void alignButtons(boolean left, boolean top) { LayoutParams params; // 触发转换以在下一次布局传递后运行 if (mStaggerCB.isChecked()) { TransitionManager.beginDelayedTransition(mSceneRoot, mStaggeredTransition); } else { TransitionManager.beginDelayedTransition(mSceneRoot); } // 更改按钮堆栈的布局参数 int oldAlignmentLR = left ? ALIGN_PARENT_RIGHT : ALIGN_PARENT_LEFT; int newAlignmentLR = left ? ALIGN_PARENT_LEFT : ALIGN_PARENT_RIGHT; int oldAlignmentTB = top ? ABOVE : BELOW; int newAlignmentTB = top ? BELOW : ABOVE; params = (LayoutParams) mFirstButton.getLayoutParams(); params.addRule(top ? ALIGN_PARENT_BOTTOM : BELOW, 0); params.addRule(oldAlignmentLR, 0); params.addRule(top ? BELOW : ALIGN_PARENT_BOTTOM, top ? R.id.staggerCB : 1); params.addRule(newAlignmentLR); mFirstButton.setLayoutParams(params); params = (LayoutParams) mSecondButton.getLayoutParams(); params.addRule(oldAlignmentLR, 0); params.addRule(oldAlignmentTB, 0); params.addRule(newAlignmentLR); params.addRule(newAlignmentTB, R.id.firstButton); mSecondButton.setLayoutParams(params); params = (LayoutParams) mThirdButton.getLayoutParams(); params.addRule(oldAlignmentLR, 0); params.addRule(oldAlignmentTB, 0); params.addRule(newAlignmentLR); params.addRule(newAlignmentTB, R.id.secondButton); mThirdButton.setLayoutParams(params); params = (LayoutParams) mFourthButton.getLayoutParams(); params.addRule(oldAlignmentLR, 0); params.addRule(oldAlignmentTB, 0); params.addRule(newAlignmentLR); params.addRule(newAlignmentTB, R.id.thirdButton); mFourthButton.setLayoutParams(params); }