布局添加动画效果

1. 布局添加动画效果

① 视图 五个按钮

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:animateLayoutChanges="true"
    android:id="@+id/myLinearLayout"
    >

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

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

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

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

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

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

② java执行代码

public class MainActivity extends Activity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 找到我们设置的布局
        LinearLayout rootView = (LinearLayout)this.findViewById(R.id.myLinearLayout);

        ScaleAnimation as = new ScaleAnimation(0, 1, 0, 1);  // 缩放动画
        as.setDuration(5000); //动画时间5s

        // 布局动画控制器
        LayoutAnimationController lac = new LayoutAnimationController(as, 0.5f);
        lac.setOrder(LayoutAnimationController.ORDER_REVERSE); // 动画类型  从下往上  默认是从上往下
        /**
         LayoutAnimationController.ORDER_NORMAL;  //顺序显示
         LayoutAnimationController.ORDER_REVERSE; //反显示
         LayoutAnimationController.ORDER_RANDOM   //随机显示
         * */

        rootView.setLayoutAnimation(lac);

        System.out.println("onCreate");
    }
}
时间: 2024-08-02 19:21:48

布局添加动画效果的相关文章

Android开发之补间动画-布局添加动画

布局添加动画 使用步骤: 1.获取到布局的id 1 RelativeLayout ly=(RelativeLayout)findViewById(R.id.layout); 2.设置动画样式 1 ScaleAnimation sa = new ScaleAnimation(0, 1,0,1); //设置动画效果 2 sa.setDuration(3000); 3.使用布局动画管理器 1 LayoutAnimationController lac = new LayoutAnimationCont

为UIView视图切换添加动画效果

我们定义了一个动画类来实现视图切换的动画效果,这个类只包含一个类方法,可直接调用,具体代码如下: 头文件: + ? 1 2 3 4 5 6 7 8 9 10 11 12 13 #import <Foundation/Foundation.h> @interface ViewAnimation : NSObject /*============================页面切换的方法==============================     View1 表示当前页面     Vi

页面跳转添加动画效果

CATransition *animation = [CATransition animation];//初始化 [animation setDuration:0.5];//设置时间间隔 [animation setType: kCATransitionReveal]; [animation setSubtype: kCATransitionFromTop]; [animation setTimingFunction:[CAMediaTimingFunction functionWithName

PopupWindow添加动画效果

1.定义PopupWindow弹出与消失的两个动画文件,放在anim文件夹下 popup_enter.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromYDelta="100%p" and

viewpager切换添加动画效果viewpager切换添加动画效果--IT蓝豹

viewpager切换添加动画效果,本项目中主要有三种切换特效,(1):DepthPageTransformer 效果(2):RotateDownPageTransformer 每一个view切换的时候旋转(3):ZoomOutPageTransformer 效果主要实现代码:  mViewPager.setPageTransformer(true,new ZoomOutPageTransformer());  mViewPager.setPageTransformer(true,new Rot

Android中给layout下的布局文件添加动画效果

先上实现效果: 给ListView添加文本内容,文本内容添加进ListView的过程中增加动画效果 步骤一: 先定义好一个动画文件,把要实现的动画效果写好. 1.在res文件夹下创建anim文件夹 2.在anim文件夹中添加一个fd.xml(文件名自定义)文件 fd.xml内容: <!--组合动画 duration:组合动画发生的的间隔时间 --> <set android:duration="1000" xmlns:android="http://sche

intent跳转时添加动画效果实例

系统默认的intent跳转效果非常生硬,丑陋,影响用户体验,怎么添加跳转动画呢? 首先新建两个动画文件: zoomin.xml: <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/deceler

CSS3实现照片墙的布局及动画效果

目标:实现照片墙布局和鼠标经过图片时的动画效果 涉及知识点:CSS3的动画.过渡.变形(缩放),绝对定位与相对定位 疑点:绝对定位与相对定位对页面元素显示层次的影响 参考极客学院布道师iwen的课程 源码—— html部分: <!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title> <link

给Activity切换过程添加动画效果

首先,在资源文件中定义一些动画效果 例如: <scale android:duration="@android:integer/config_mediumAnimTime" android:fromXScale="1.0" android:fromYScale="1.0" android:pivotX="50%p" android:pivotY="50%p" android:toXScale=&quo