代码之家  ›  专栏  ›  技术社区  ›  M'aiq the Coder

动画:我如何使动画重复后,我参观了另一个活动,回来?

  •  0
  • M'aiq the Coder  · 技术社区  · 6 年前

    我想知道如何使动画复出后,在特定的网页上重复。我的动画基本上是在你访问某个活动时,将一个相对位置向下平移几个像素。但是,如果我点击一个按钮,将我发送到另一个页面,然后点击后退按钮返回,翻译动画就不会再开始了。

    代码如下:

    RelativeLayout r1;
    
        r1 = findViewById(R.id.r1);
    
        TranslateAnimation a = new TranslateAnimation(0,0,-10f,0);
        a.setDuration(800);
        a.setFillAfter(true);
        r1.startAnimation(a);
    

    每次访问活动时,如何使动画重新启动?

    2 回复  |  直到 6 年前
        1
  •  2
  •   Sasi Kumar    6 年前

    void myanimation(){
    TranslateAnimation a = new TranslateAnimation(0,0,-10f,0);
    a.setDuration(800);
    a.setFillAfter(true);
    r1.startAnimation(a);
    }
    

    然后调用activity onResume中的方法

    @Override
    public void onResume(){
    super.onResume();
    myanimation();
    
    }
    
        2
  •  1
  •   Erselan Khan    6 年前

    在onResume()方法中使用这个。每次与活动交互时,都会调用OnResume。