Android动画(透明度,平移,旋转,拉伸,动态添加按钮)

步骤:

透明度变化

状态图:

这里写图片描述

代码:

  //透明度变化
                AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f);//第一个参数开始的透明度,第二个参数结束的透明度
                alphaAnimation.setDuration(3000);//多长时间完成这个动作
                imageView1.startAnimation(alphaAnimation);

平移:

状态图:

这里写图片描述

代码:

 //平移
                TranslateAnimation animation = new TranslateAnimation(0,imageView1.getMeasuredWidth(), 0, 0);
 //前两个参数是设置x轴的起止位置,后两个参数设置y轴的起止位置               
                animation.setDuration(3000);
                imageView2.startAnimation(animation);

旋转:

状态图:

这里写图片描述

代码:

 //旋转中心是(0,0)
                RotateAnimation rotateAnimation = new RotateAnimation(0,360);
                第一个参数是旋转中心,第二个是旋转角度,旋转中心(0~100%)
                rotateAnimation.setDuration(3000);
                imageView3.startAnimation(rotateAnimation);

拉伸:

状态图:

这里写图片描述

代码:

 //拉伸
                ScaleAnimation scaleAnimation=new ScaleAnimation(1,0.5f,1,0.5f);//默认从(0,0)
                scaleAnimation.setDuration(3000);
                imageView4.startAnimation(scaleAnimation);

源码:

layout

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <Button
            android:id="@+id/button_start_animation"
            android:text="开始动画"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <ImageView
            android:id="@+id/animation_imageview5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/b"/>
        <ImageView
            android:id="@+id/animation_imageview1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/b"/>
        <ImageView
            android:id="@+id/animation_imageview2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/b"/>
        <ImageView
            android:id="@+id/animation_imageview3"
            android:layout_width="wrap_content"
            android:layout_height=
  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值