gpt4 book ai didi

Android:动画完成后更新 LinearLayout 位置

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

对于以下问题的任何帮助将不胜感激。我知道我需要做什么,并且我已经检查了开发人员文档,但我不知道我需要使用的确切语法(我是菜鸟)。

这就是我正在做的。我在 res/anim 中有一个可以正常工作的 translate.xml 文件。它看起来像这样:

<translate xmlns:android="http://schemas.android.com/apk/res/android" 
android:fromXDelta="0%"
android:toXDelta="0%"
android:fromYDelta="0%"
android:toYDelta="10%"
android:repeatCount="0"
android:duration="1000"
android:fillEnabled="true"
android:fillAfter="true"/>

我正在这样执行我的代码:

    l = (LinearLayout) findViewById(R.id.linearLayout1);
a = AnimationUtils.loadAnimation(this, R.anim.translate);
a.setAnimationListener(new AnimationListener() {
public void onAnimationStart(Animation anim){};
public void onAnimationRepeat(Animation anim){};
public void onAnimationEnd(Animation anim){
//l.setLayoutParams(params);
};
});
l.startAnimation(a);

当动画完成后,我希望它动画的 LinearLayout 移动到它的新位置(动画将它移动到的位置)。这是因为 LinearLayout 包含多个用户可以与之交互的表单元素。

对于一个相当简单的项目来说,这是一个真正简单的动画。它只是将元素向下移动屏幕大约 30 像素。我不会寻求帮助,除非我已经为此苦苦挣扎了几个小时。我知道我需要在动画结束时更新 LinearLayout 的参数,但具体怎么做呢?我读过几种不同的方法,但它们都有点令人困惑。

提前致谢。

最佳答案

与其创建新的 AnimationListener,不如尝试为当前(或新)类实现 AnimationListener 接口(interface)。然后只需覆盖 onAnimationEnd() 方法即可。

例子:

public class ThisClass implements AnimationListener {

private otherMethod() {
l.getAnimation().setAnimationListener(this);
}

public void onAnimationStart(Animation anim){};
public void onAnimationRepeat(Animation anim){};
public void onAnimationEnd(Animation anim){
l.setLayoutParams(params);
};

关于Android:动画完成后更新 LinearLayout 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5822661/

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