我有一组视图能够在屏幕上移动并随后反转但现在当我尝试移动一个CardView时它将会关闭但不会备份。
当用户单击按钮时,它会提示视图集合下拉/淡出,当用户再次单击该按钮时,它们将返回。在视图消失的集合创建的空间中,CardView会下降。我有CardView下拉但是当用户点击按钮时,视图集合返回但不是CardView - 而是它消失了。干杯!
MainActivity(注意:在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);
}
}
});
答案 0 :(得分:1)
每次click_Animation_Type
都以0开头。将click_Animation_Type = 0;
图层放在setContentView
下方。