gpt4 book ai didi

java - ObjectAnimator 不反转

转载 作者:行者123 更新时间:2023-12-02 12:17:19 27 4
gpt4 key购买 nike

我有一组 View 能够在屏幕上向下移动并随后反向移动,但现在当我尝试移动 CardView 时,它会向下移动但不会向上移动。

当用户单击按钮时,它会提示 View 集合下拉/消失,当用户再次单击该按钮时,它们会返回。在 View 集合消失所创建的空间中,一个 CardView 落下。我有要下拉的 CardView,但是当用户单击按钮时, View 集合会返回,但不会返回 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);
}
}

});

最佳答案

每次click_Animation_Type都从0开始。将click_Animation_Type = 0;层放在setContentView下面。

关于java - ObjectAnimator 不反转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46066918/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com