代码之家  ›  专栏  ›  技术社区  ›  Milan

使用布局动画时重新激活视图

  •  0
  • Milan  · 技术社区  · 14 年前

    在我的一个视图上使用布局动画。

    android:layoutAnimation="@anim/animate_layout"
    

    onresume() 方法并从那里调用它。

    如何从代码中调用layoutImation以便在整个布局中再次运行它?

    3 回复  |  直到 14 年前
        1
  •  1
  •   Cristian    14 年前

    Animation animation = AnimationUtils.loadAnimation(ctx, android.R.anim.fade_out);
    target.startAnimation(animation);    
    

    在哪里? ctx 可能是这样的 YourActivity.this ,目标是 View 你想制作动画。

        2
  •  0
  •   Pentium10    14 年前
        3
  •  0
  •   Martin    14 年前

    我还试图让我的动画重新开始,当用户再次获得se布局。我很快就完成了这个代码。

    public void onResume(){
         super.onResume();
         View layout = findViewById(R.layout.main);
         Animation animation = AnimationUtils.loadAnimation(CrookTranslate.this, R.anim.fade_from_left);
         layout.startAnimation(animation);        
        }   
    
    <?xml version="1.0" encoding="utf-8"?>
    <layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
    android:animation="@anim/from_left"
    android:id="@+id/fade_from_left"
    android:delay="3.0"
    /> 
    

    enter code here