将布局从左到右排列

huangapple go评论69阅读模式
英文:

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();

huangapple
  • 本文由 发表于 2020年10月12日 18:25:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/64315995.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定