Skip to content

Instantly share code, notes, and snippets.

@RamiJ3mli
Created August 22, 2018 17:09
Show Gist options
  • Save RamiJ3mli/2489adfcf1eef6c36197d1e09cb52cf4 to your computer and use it in GitHub Desktop.
Save RamiJ3mli/2489adfcf1eef6c36197d1e09cb52cf4 to your computer and use it in GitHub Desktop.
@BindView(R.id.constraint_layout)
ConstraintLayout mConstraintLayout;
ConstraintSet constraintSet;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
ButterKnife.bind(this);
constraintSet = new ConstraintSet();
constraintSet.clone(mConstraintLayout);
}
private void animate(byte view) {
Transition transition = new ChangeBounds();
transition.setDuration(400);
transition.setInterpolator(new OvershootInterpolator(3));
TransitionManager.beginDelayedTransition(mConstraintLayout, transition);
switch (view) {
case 0:
constraintSet.centerHorizontally(R.id.selector, R.id.space_background);
constraintSet.centerVertically(R.id.selector, R.id.space_background);
break;
case 1:
constraintSet.centerHorizontally(R.id.selector, R.id.science_background);
constraintSet.centerVertically(R.id.selector, R.id.science_background);
break;
case 2:
constraintSet.centerHorizontally(R.id.selector, R.id.ai_background);
constraintSet.centerVertically(R.id.selector, R.id.ai_background);
break;
case 3:
constraintSet.centerHorizontally(R.id.selector, R.id.nature_background);
constraintSet.centerVertically(R.id.selector, R.id.nature_background);
break;
}
constraintSet.applyTo(mConstraintLayout);
}
@OnClick(R.id.space_background)
public void spaceAction() {
animate((byte) 0);
}
@OnClick(R.id.science_background)
public void scienceAction() {
animate((byte) 1);
}
@OnClick(R.id.ai_background)
public void aiAction() {
animate((byte) 2);
}
@OnClick(R.id.nature_background)
public void natureAction() {
animate((byte) 3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment