gpt4 book ai didi

android - android动画中setfillafter(true)后 View 的实际位置没有改变

转载 作者:太空狗 更新时间:2023-10-29 12:52:23 25 4
gpt4 key购买 nike

我正在通过这段代码移动 View ,但是 View 的实际位置没有改变,为什么

                TranslateAnimation ta = new TranslateAnimation(0, 0, Animation.RELATIVE_TO_SELF, -mbar4.getHeight());
ta.setDuration(1000);
ta.setFillAfter(true);
v4.startAnimation(ta);

最佳答案

直到第 3 版(API 11)的 android 除外,所有动画都不会真正改变 View ,只会改变它的显示方式。不仅如此,我认为他们根本不使用 GPU。

为了检查它,您可以使用一个按钮并为它设置 OnClickListener,看看无论您使用哪种动画,点击都只会在其原始位置和大小上起作用。

这是使用 translateAnimation 移动 View 的示例代码:

final int deltaXToMove=50;
TranslateAnimation translateAnimation=new TranslateAnimation(0,deltaXToMove,0,0);
int animationTime=1000;
translateAnimation.setDuration(animationTime);
translateAnimation.setFillEnabled(true);
translateAnimation.setFillAfter(true);
final Button b=(Button)findViewById(R.id.button);
translateAnimation.setAnimationListener(new AnimationListener()
{
@Override
public void onAnimationEnd(Animation animation)
{
animation.setFillAfter(false);
FrameLayout.LayoutParams par=(LayoutParams)b.getLayoutParams();
par.leftMargin=deltaXToMove;
b.setLayoutParams(par);
}
...
b.startAnimation(translateAnimation);

关于android - android动画中setfillafter(true)后 View 的实际位置没有改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10946699/

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