Animations使用 (四)
16lz
2022-04-12
Animations的第二种使用方法(第一种见1)
步骤:
1 在res文件夹线面新建一个名为anim的文件夹
2 创建xml文件,并首先加入set标签,改标签如下
3 在该标签中加入rotate,alpha,scale或者translate标签
例:
Alpha的alpha.xml文件编写方法(这些标签都是放在set标签中的)
rotate.xml
这里要特别注意跟位置有关的参数pivotX和pivotY
3种写法对应3种相对位置方式的设置方式:
android:pivotX="50" 绝对定位
android:pivotX="50%" 相对于控件本身
android:pivotX="50%p" 相对于父控件
translate.xml
scale.xml
4 在代码中使用AnimationUtils装载xml文件,并生成Animation对象
步骤:
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);
更多相关文章
- Android(安卓)-- 设置textview文字居中或者控件居中
- 三种方法使android 手机执行 二进制程序
- Android_判断文件是否存在并创建代码
- Android(安卓)pm命令使用方法
- Android这可能是当今最火,功能最全的快速开发框架了
- 如何制作Jar包并在android中调用jar包
- Android(安卓)Html类
- mybatisplus的坑 insert标签insert into select无参数问题的解决
- NPM 和webpack 的基础使用