I have a collection of Views able to move down the screen and subsequently reverse but now as I try to move a CardView it will go down but not back up.
When the User clicks a button, it prompts the collection of Views to drop down/fade away and when the User clicks the button again they return. In the space created by the collection of Views vanishing, a CardView drops down. I have the CardView to drop down but when the User clicks the button, the collection of views return but not the CardView - instead it just vanishes. Cheers!
MainActivity (NB: in OnCreate())
...
final View blankCard = findViewById(R.id.child_card_template);
blankCard.setVisibility(blankCard.INVISIBLE);
...
ImageButton btn = (ImageButton) findViewById(R.id.imageLeft);
btn.setOnClickListener(new View.OnClickListener() {
int click_Animation_Type = 0;
View viewTest = findViewById(R.id.child_card_template);
View viewCard = viewTest;
@Override
public void onClick(View view) {
switch(click_Animation_Type) {
case 0:
moveSecondRow();
moveCardViewLayout();
click_Animation_Type = 1;
break;
case 1:
rewindSecondRow();
rewindCardViewLayout();
click_Animation_Type = 0;
break;
}
}
public void moveCardViewLayout() {
View viewTest = findViewById(R.id.child_card_template);
ObjectAnimator viewTestMovi = ObjectAnimator.ofFloat(viewTest, "translationY", 0f, 258f);
if(viewTest.getVisibility()==View.INVISIBLE) {
viewTestMovi.setDuration(250);
viewTestMovi.start();
viewTest.setVisibility(viewTest.VISIBLE);
}
}
public void rewindCardViewLayout() {
View viewTest = findViewById(R.id.child_card_template);
ObjectAnimator viewTestMoviReverse = ObjectAnimator.ofFloat(viewTest, "translationY", 258f, 0f);
if (viewTest.getVisibility() == View.VISIBLE) {
viewTestMoviReverse.setDuration(250);
viewTestMoviReverse.start();
viewTest.setVisibility(viewCard.INVISIBLE);
//THERE'S NO ANIMATION, JUST TURNING INVISIBLE.
//Registers View is visible.
}
}
public void moveSecondRow() {
for (int i = 0; i < list.size(); i++) {
ObjectAnimator bottomRow = ObjectAnimator.ofFloat(list.get(i), "translationY", 0f, 300f);
bottomRow.setDuration(250);//set duration
Animation fadeOutAnimation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_out_anim);
bottomRow.start();//start animation
list.get(i).startAnimation(fadeOutAnimation);
list.get(i).setVisibility(View.GONE);
}
}
public void rewindSecondRow() {
for (int i = 0; i < list.size(); i++) {
ObjectAnimator bottomRow = ObjectAnimator.ofFloat(list.get(i), "translationY", 300f, 0f);
bottomRow.setDuration(300);//set duration
Animation fadeInAnimation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade_in_anim);
bottomRow.start();//start animation
list.get(i).setVisibility(View.VISIBLE);
list.get(i).startAnimation(fadeInAnimation);
}
}
});
every time click_Animation_Type
starts with 0. Put click_Animation_Type = 0;
layer below the setContentView
.