`
chengfengyang
  • 浏览: 21155 次
社区版块
存档分类
最新评论

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);

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics