Animations使用 (四)

Animations的第二种使用方法(第一种见1)

步骤:

1 在res文件夹线面新建一个名为anim的文件夹



2 创建xml文件,并首先加入set标签,改标签如下

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
...
</set>


3 在该标签中加入rotate,alpha,scale或者translate标签

例:

Alpha的alpha.xml文件编写方法(这些标签都是放在set标签中的)

<alpha android:fromAlpha="1.0"
android:toAlpha="0.0"
android:atartOffset="500"
android:duration="500" />


rotate.xml
<rotate android:fromDegrees="0"
android:toDegrees="+350" //正350度
android:pivotX="50%"
android:pivotY="50%"
android:duration="3000" />


这里要特别注意跟位置有关的参数pivotX和pivotY

3种写法对应3种相对位置方式的设置方式:

android:pivotX="50" 绝对定位

android:pivotX="50%" 相对于控件本身

android:pivotX="50%p" 相对于父控件



translate.xml

<translate android:fromXDelta="50%"
android:toXDelta="100%"
android:fromYDelta="0%"
android:toYDelta="100%"
android:duration="1000" />


scale.xml
<scale android:fromXScale="1.0"
android:toXScale="0.0"
android:fromYScale="1.0"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="2000" />


4 在代码中使用AnimationUtils装载xml文件,并生成Animation对象

Animation animation=AnimationUtils.loadAnimation(MainActivity.this, R.anim.alpha);  //载入布局文件
imageView.startAnimation(animation);

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值