Reputation: 33
I have a transition applied to several buttons where I try to change their width from 0dp to MATCH_PARENT
final ChangeBounds transition = new ChangeBounds();
startFloat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
for(i=0;i<allCards.size();i++) {
if(i%2 == 0) {
transition.setDuration(4000L);
TransitionManager.beginDelayedTransition(allCards.get(i), transition);
allButton.get(i).setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dp10));
}
else{
transition.setDuration(400L);
TransitionManager.beginDelayedTransition(allCards.get(i), transition);
allButton.get(i).setLayoutParams(new MaterialCardView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dp10));
}
}
}
});
Note: dp10 is an integer variable (No problem there).
This seems to work fine, however, when I click startFloat
button, all the transitions occur at the same time. I want them to start after the previous one ends.
Any idea of how to achieve the same?
Upvotes: 0
Views: 507
Reputation: 33
I was able to solve my problem by using transition.setStartDelay(delay)
.
Here is my code:
final ChangeBounds transition = new ChangeBounds();
startFloat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
for(int i=0;i<allCards.size();i++) {
if(i%2 == 0) {
transition.setDuration(4000L);
transition.setStartDelay(delay);
TransitionManager.beginDelayedTransition(allCards.get(i), transition);
allButton.get(i).setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dp10));
delay+=4000;
}
else{
transition.setDuration(400L);
transition.setStartDelay(delay);
TransitionManager.beginDelayedTransition(allCards.get(i), transition);
allButton.get(i).setLayoutParams(new MaterialCardView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dp10));
delay+=400;
}
}
}
});
Upvotes: 0
Reputation: 1875
I have faced the same problem few days ago. The solution is , you need to use different transitions for different views. You need to create two transitions here and use each of them once only. Try this
final ChangeBounds firestTransition = new ChangeBounds();
final ChangeBounds secondTransition= new ChangeBounds();
startFloat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
for(i=0;i<allCards.size();i++) {
if(i%2 == 0) {
firestTransition.setDuration(4000L);
TransitionManager.beginDelayedTransition(allCards.get(i), transition);
allButton.get(i).setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dp10));
}
else{
secondTransition.setDuration(400L);
TransitionManager.beginDelayedTransition(allCards.get(i), transition);
allButton.get(i).setLayoutParams(new MaterialCardView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dp10));
}
}
}
});
Upvotes: 0
Reputation: 2824
You should use TransitionSet
instead so you can configure that order as sequential. More details here and here in the official Android docs
Upvotes: 1