英文:
Translate Layout left to right
问题
我尝试使用这个代码来实现布局的翻译动画。但它只能从左到右进行布局平移。但我需要从右到左进行平移。那我应该如何做呢?
aLayout.animate()
.translationX(-bLrLayout.getWidth()) // 注意这里的负值
.alpha(0.0f)
.setDuration(3000);
英文:
I tried to make a layout translation animate with this. But it only translate layout from left to right. But I need to translate right to left. So how should I do that?
aLayout.animate()
.translationX(bLrLayout.getHeight())
.alpha(0.0f)
.setDuration(3000);
答案1
得分: 1
> 但是我需要从右向左进行翻译。
只需将负数作为 translationX
参数即可:
aLayout.animate()
.translationX(-1000)
.alpha(0.0f)
.setDuration(3000);
英文:
> But I need to translate right to left.
just use negative number as translationX
parameter
aLayout.animate()
.translationX(-1000)
.alpha(0.0f)
.setDuration(3000);
答案2
得分: 0
你可以像这样做:
ObjectAnimator anim = ObjectAnimator.ofFloat(this, "translationX", 0, bLrLayout.getHeight());
anim.start();
然后如果你想返回:
ObjectAnimator anim = ObjectAnimator.ofFloat(this, "translationX", bLrLayout.getHeight(), 0);
anim.start();
英文:
you can do something like this
ObjectAnimator anim = ObjectAnimator.ofFloat(this, "translationX", 0, bLrLayout.getHeight());
anim.start();
and then if you want to return back
ObjectAnimator anim = ObjectAnimator.ofFloat(this, "translationX", bLrLayout.getHeight(), 0);
anim.start();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论