AndroidUI 布局动画-为布局添加动画

除了可以为视图添加动画以外,还可以为视图的布局添加动画;

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:orientation="vertical" 
        android:id="@+id/linerLayout1">

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
    </LinearLayout>

</RelativeLayout>

代码:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        LinearLayout layout= (LinearLayout)findViewById(R.id.linerLayout1);
        
        //设置缩放动画
        ScaleAnimation scale=new ScaleAnimation(0, 1, 0, 1);
        scale.setDuration(3000);
        //delay(动画延迟):0~1f,当第一个动画执行到什么地方的时候,下一个动画开始执行
        //LayoutAnimationController controller=new LayoutAnimationController(scale, 0);
        LayoutAnimationController controller=new LayoutAnimationController(scale, 0.5f);
        //动画的执行顺序:ORDER_NORMAL(从上往 下);ORDER_RANDOM(随机执行);ORDER_REVERSE(从下往上)
       // controller.setOrder(LayoutAnimationController.ORDER_NORMAL);
        controller.setOrder(LayoutAnimationController.ORDER_REVERSE);
        layout.setLayoutAnimation(controller);
    }
<pre name="code" class="java">//LayoutAnimationController controller=new LayoutAnimationController(scale, 0); //内部动画同时执行

 



<pre name="code" class="java">LayoutAnimationController controller=new LayoutAnimationController(scale, 0.5f); //内部动画延时执行
 
动画的执行顺序:ORDER_NORMAL(从上往 下):

ORDER_REVERSE(从下往上)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值