首页 > 代码库 > [2017-8-02]Android Learning Day9

[2017-8-02]Android Learning Day9

Layout动画效果

 

为布局添加简单的动画效果

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(activity_main);

        //设置一个动画效果
        ScaleAnimation sa = new ScaleAnimation(0,1,0,1, Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
        sa.setDuration(1000);
        
        //设置一个布局动画控制器,配置动画,和延迟(delay)
        //延迟是指布局中的子项目在上一个完成f%后再加载,相当于依次进行
        LayoutAnimationController lac = new LayoutAnimationController(sa, 0.2f);
        
        //通过id找到布局,并设置布局动画控制器
        ((LinearLayout) findViewById(R.id.layout)).setLayoutAnimation(lac);
    }
}

 

[2017-8-02]Android Learning Day9