UI设计篇·入门篇·简单动画的实现,为布局设置动画,用XML布置布局动画

不仅仅控件可以设置动画,一个布局也可以设置动画,

当给一个布局设置了动画的时候,这个布局里所包含的控件都会依赖执行这些动画。

为布局设置动画的实现步骤:

1.新建一个动画,设置需要实现的形式

2.新建一个LayoutAnimationController,将新建的动画添加进LayoutAnimationController,设置延时时间

3.使用setLayoutAnimation()方法,为该布局设置动画,当动画设置后,启动时就会自动执行

实际代码:

ScaleAnimation scaleAnimation = new ScaleAnimation(0,1,0,1);
scaleAnimation.setDuration(
1000); LayoutAnimationController controller = new LayoutAnimationController(scaleAnimation,0.5f); LinearLayout root = (LinearLayout) findViewById(R.id.fog); if (root != null) {   root.setLayoutAnimation(controller); }


也可以使用XML文件配置布局动画,通过设置属性的方法使用布局动画

设置布局XML的代码:

<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
    android:animation="@anim/scaleanimation"  //这是一个已经设置好的布局动画
    android:delay="0.5">              //设置0.5的延时
</layoutAnimation>

在布局控件中使用XML文件配饰的动画的方法:

<ListView
  android:layout_width
="wrap_content" android:layout_height="wrap_content" android:id="@+id/list" android:layoutAnimation="@anim/layout_animation">
</ListView>
原文地址:https://www.cnblogs.com/thinfog/p/5712602.html