zoukankan      html  css  js  c++  java
  • 安卓xml动画

    1.淡入淡出效果:

    在res—下新建文件夹anim(animation的简称)

    anim下新建文件demo.xml

    <set xmlns:android="http://schemas.android.com/apk/res/android">
        <alpha
            android:fromAlpha="0.5"
            android:toAlpha="1.0"
            android:duration="1000"  />
    </set>
        <!--
            fromAlpha:开始时透明度
            toAlpha: 结束时透明度
            duration:动画持续时间 -->

    布局:

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical">
    
            <ImageView
                android:id="@+id/imageView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@mipmap/lg" />
        </LinearLayout>

    代码:

    final ImageView imageView = (ImageView) findViewById(R.id.imageView);
            final Animation animation = AnimationUtils.loadAnimation(this, R.anim.demo);
            fab.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    imageView.startAnimation(animation);
                }
            });

    更多属性:

    <?xml version="1.0" encoding="utf-8"?>
    <alpha xmlns:android="http://schemas.android.com/apk/res/android"
          android:duration="3000"
          android:fillAfter="true"
          android:fillBefore="false"
          android:fromAlpha="1.0"
          android:interpolator="@android:anim/linear_interpolator"
          android:repeatCount="-1"
          android:repeatMode="restart"
          android:startOffset="2000"
          android:toAlpha="0.3"/>
    <!--
    android:duration:动画持续的时长,单位是毫秒
    android:fillAfter:动画结束之后是否保持动画的最终状态;true,表示保持动画的最终状态
    android:fillBefore:动画结束之后是否保持动画开始前的状态;true,表示恢复到动画开始前的状态
    android:fromAlpha:动画开始的透明度,取值0.0~1.0,0.0表示完全透明,1.0表示保持原有状态不变
    android:interpolator:动画插值器。是实现动画不规则运动的一种方式,后面讲到
    android:repeatCount:动画重复的次数。指定动画重复播放的次数,如果你需要无限循环播放,请填写一个小于0的数值,我一般写-1
    android:repeatMode:动画重复的Mode,有reverse和restart两种,效果看后面
    android:startOffset:动画播放延迟时长,就是调用start之后延迟多少时间播放动画
    android:toAlpha:动画最终的透明度,取值和android:fromAlpha一样
    -->

    可以用于app的加载页, 图片淡入的效果不错。

  • 相关阅读:
    基础之实战猜年龄游戏
    基本运算符与if while详解:
    while循环练习:
    常量与格式化输出练习
    Flask基础(05)-->路由的基本定义
    Flask基础(04)-->相关配置参数
    Flask基础(03)-->创建第一个Flask程序
    Flask基础(02)-->搭建Flask项目虚拟环境
    Flask基础(01)-->Flask框架介绍
    Flask实战第61天:帖子板块过滤显示
  • 原文地址:https://www.cnblogs.com/6324/p/6928783.html
Copyright © 2011-2022 走看看