트랜지션은 장면이 전환될 때의 애니메이션에 대한 정보를 담고 있는 추상 클래스
Transition 방식은 SDKVersion 21 이상부터 지원하기 때문에 그 이하의 버전에서는 사용이 불가능
Transitions API
dependencies {
compile "com.andkulikov:transitionseverywhere:1.6.5"
}
```java
TransitionManager.beginDelayedTransition(layoutFrame);
if(text.getVisibility() == View.VISIBLE){
text.setVisibility(View.GONE);
} else {
text.setVisibility(View.VISIBLE);
}
```
```java
TransitionManager.beginDelayedTransition(layoutFrame, new Slide(Gravity.RIGHT));
if(text.getVisibility() == View.VISIBLE){
text.setVisibility(View.GONE);
} else {
text.setVisibility(View.VISIBLE);
}
```
```java
TransitionSet set = new TransitionSet()
.addTransition(new Scale(0.7f))
.addTransition(new Fade());
if(text.getVisibility() == View.VISIBLE){
set.setInterpolator(new FastOutLinearInInterpolator());
TransitionManager.beginDelayedTransition(layoutFrame, set);
text.setVisibility(View.INVISIBLE);
} else {
set.setInterpolator(new LinearOutSlowInInterpolator());
TransitionManager.beginDelayedTransition(layoutFrame, set);
text.setVisibility(View.VISIBLE);
}
```
RECOLOR
```java
TransitionManager.beginDelayedTransition(layoutFrame, new Recolor());
if(button.getCurrentTextColor() == getResources().getColor(R.color.colorPrimary)){
button.setTextColor(getResources().getColor(R.color.colorAccent));
button.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
} else {
button.setTextColor(getResources().getColor(R.color.colorPrimary));
button.setBackgroundColor(getResources().getColor(R.color.colorAccent));
}
```
ROTATE
```java
TransitionManager.beginDelayedTransition(layoutFrame, new Rotate());
if(image.getRotation() == 0){
image.setRotation(90);
} else {
image.setRotation(0);
}
```
```java
TransitionManager.beginDelayedTransition(layoutFrame,
new ChangeText().setChangeBehavior(ChangeText.CHANGE_BEHAVIOR_OUT_IN));
if(text.getText().equals("Hello")){
text.setText("World");
} else {
text.setText("Hello");
}
```
```java
private class ProgressTransition extends Transition {
/**
* Property is like a helper that contain setter and getter in one place
*/
private static final Property<ProgressBar, Integer> PROGRESS_PROPERTY =
new IntProperty<ProgressBar>() {
@Override
public void setValue(ProgressBar progressBar, int value) {
progressBar.setProgress(value);
}
@Override
public Integer get(ProgressBar progressBar) {
return progressBar.getProgress();
}
};
/**
* Internal name of property. Like a intent bundles
*/
private static final String PROPNAME_PROGRESS = "ProgressTransition:progress";
@Override
public void captureStartValues(TransitionValues transitionValues) {
captureValues(transitionValues);
}
@Override
public void captureEndValues(TransitionValues transitionValues) {
captureValues(transitionValues);
}
private void captureValues(TransitionValues transitionValues) {
if (transitionValues.view instanceof ProgressBar) {
// save current progress in the values map
ProgressBar progressBar = ((ProgressBar) transitionValues.view);
transitionValues.values.put(PROPNAME_PROGRESS, progressBar.getProgress());
}
}
@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues,
TransitionValues endValues) {
if (startValues != null && endValues != null && endValues.view instanceof ProgressBar) {
ProgressBar progressBar = (ProgressBar) endValues.view;
int start = (Integer) startValues.values.get(PROPNAME_PROGRESS);
int end = (Integer) endValues.values.get(PROPNAME_PROGRESS);
if (start != end) {
// first of all we need to apply the start value, because right now
// the view is have end value
progressBar.setProgress(start);
// create animator with our progressBar, property and end value
return ObjectAnimator.ofInt(progressBar, PROGRESS_PROPERTY, end);
}
}
return null;
}
}
// ------------------------------------------------------------------------------------
ProgressTransition progressTransition = new ProgressTransition();
progressTransition.setDuration(1000);
TransitionManager.beginDelayedTransition(layoutFrame, progressTransition);
progressBar.setProgress(100);
```