Android之Animation<2>
Animations的第二种使用方法
1.在res文件夹下新建一个anim的 文件夹;
2.创建xml文件,首先加入set便签,改标签如下:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
</set>3.在该标签当中加入alpha、rotate、scale或translate标签
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<translate
android:fromXDelta="50%p"
android:toXDelta="0"
android:fromYDelta="50%p"
android:toYDelta="0"
android:duration="3000"/>
</set>4.在代码当中使用AnimationUtils加载xml文件,并生成Animation对象
translate_btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.translate);
image.startAnimation(animation);
}
});重点解释:
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="4000"/>android:pivotX的值共有三种设置方法
1.android:pivotX=“50”
这种方法使用绝对位置定位,也就是像素的绝对值,但是(0,0)并不是相对于父控件而言的,不是屏幕的左上角,而是view的左上角,以view左上角为(0,0)点;
2.android:pivotX="50%“
这种方法相对于view本身而言,pivotX,pivotY都为50%,则为view的中心
3.android:pivotX=”50%p“
这种方法相对于view的父控件定位,pivotX,pivotY都为50%P,并不是旋转点就在屏幕的中心,它的(0, 0)点也是view的左上角,pivotX,pivotY都为50%P意思是view左上角的横坐标加上父控件屏幕的一半像素长度为旋转点的横坐标,纵坐标如是;
相关推荐
xfcyhades 2020-11-20
Michael 2020-11-03
业余架构师 2020-10-09
OuNuo0 2020-09-29
moses 2020-09-22
Angelia 2020-09-11
qinxu 2020-09-10
刘炳昭 2020-09-10
Nostalgiachild 2020-09-07
Nostalgiachild 2020-08-17
leavesC 2020-08-14
一青年 2020-08-13
AndroidAiStudy 2020-08-07
ydc0 2020-07-30
绿豆饼 2020-07-28