| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package com.android.transitiontests; |
| 17 |
|
| 18 |
import android.app.Activity; |
| 19 |
import android.os.Bundle; |
| 20 |
import android.transition.ChangeBounds; |
| 21 |
import android.view.View; |
| 22 |
import android.view.ViewGroup; |
| 23 |
import android.transition.Transition; |
| 24 |
import android.transition.TransitionSet; |
| 25 |
import android.transition.TransitionManager; |
| 26 |
import android.widget.Button; |
| 27 |
|
| 28 |
import static android.widget.LinearLayout.LayoutParams; |
| 29 |
|
| 30 |
public class HierarchicalMove extends Activity { |
| 31 |
|
| 32 |
Button[] buttons = new Button[6]; |
| 33 |
ViewGroup mSceneRoot; |
| 34 |
boolean wide = false; |
| 35 |
Transition mTransition; |
| 36 |
|
| 37 |
@Override |
| 38 |
public void onCreate(Bundle savedInstanceState) { |
| 39 |
super.onCreate(savedInstanceState); |
| 40 |
setContentView(R.layout.hierarchical_move); |
| 41 |
|
| 42 |
View container = (View) findViewById(R.id.container); |
| 43 |
mSceneRoot = (ViewGroup) container.getParent(); |
| 44 |
|
| 45 |
buttons[0] = (Button) findViewById(R.id.button0); |
| 46 |
buttons[1] = (Button) findViewById(R.id.button1); |
| 47 |
buttons[2] = (Button) findViewById(R.id.button2); |
| 48 |
buttons[3] = (Button) findViewById(R.id.button3); |
| 49 |
buttons[4] = (Button) findViewById(R.id.button4); |
| 50 |
buttons[5] = (Button) findViewById(R.id.button5); |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
TransitionSet rootTransition = new TransitionSet(). |
| 63 |
setOrdering(TransitionSet.ORDERING_SEQUENTIAL); |
| 64 |
|
| 65 |
|
| 66 |
Transition move0 = new ChangeBounds(); |
| 67 |
move0.addTarget(buttons[0]); |
| 68 |
|
| 69 |
|
| 70 |
TransitionSet group12345 = new TransitionSet(). |
| 71 |
setOrdering(TransitionSet.ORDERING_SEQUENTIAL); |
| 72 |
|
| 73 |
|
| 74 |
TransitionSet group12 = new TransitionSet(). |
| 75 |
setOrdering(TransitionSet.ORDERING_TOGETHER); |
| 76 |
ChangeBounds changeBounds1 = new ChangeBounds(); |
| 77 |
changeBounds1.addTarget(buttons[1]); |
| 78 |
ChangeBounds changeBounds2 = new ChangeBounds(); |
| 79 |
changeBounds2.addTarget(buttons[2]); |
| 80 |
group12.addTransition(changeBounds1).addTransition(changeBounds2); |
| 81 |
|
| 82 |
TransitionSet group345 = new TransitionSet(). |
| 83 |
setOrdering(TransitionSet.ORDERING_SEQUENTIAL); |
| 84 |
ChangeBounds changeBounds3 = new ChangeBounds(); |
| 85 |
changeBounds3.addTarget(buttons[3]); |
| 86 |
ChangeBounds changeBounds45 = new ChangeBounds(); |
| 87 |
changeBounds45.addTarget(buttons[4]).addTarget(buttons[5]); |
| 88 |
group345.addTransition(changeBounds3).addTransition(changeBounds45); |
| 89 |
|
| 90 |
group12345.addTransition(move0).addTransition(group12).addTransition(group345); |
| 91 |
|
| 92 |
rootTransition.addTransition(group12345); |
| 93 |
rootTransition.setDuration(1000); |
| 94 |
mTransition = rootTransition; |
| 95 |
|
| 96 |
} |
| 97 |
|
| 98 |
public void sendMessage(View view) { |
| 99 |
TransitionManager.beginDelayedTransition(mSceneRoot, mTransition); |
| 100 |
int widthSpec = wide ? LayoutParams.WRAP_CONTENT : LayoutParams.MATCH_PARENT; |
| 101 |
LayoutParams params = new LayoutParams(widthSpec, LayoutParams.WRAP_CONTENT); |
| 102 |
for (int i = 0; i < buttons.length; ++i) { |
| 103 |
buttons[i].setLayoutParams(params); |
| 104 |
} |
| 105 |
wide = !wide; |
| 106 |
} |
| 107 |
|
| 108 |
} |