8:Frame Animation:(逐帧动画)、Tween Animation:(补间动画)

一:Frame Animation:(逐帧动画)

这个很好理解,一帧帧的播放图片,利用人眼视觉残留原理,给我们带来动画的感觉。它的原理的GIF图片、电影播放原理一样。

1.定义逐帧动画比较简单,只要在中使用子元素定义所有播放帧即可。

frame.xml

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
     android:oneshot="false">  
    <item android:drawable="@drawable/f1" android:duration="1000" />  //第一帧到下一帧的时间间隔
    <item android:drawable="@drawable/f2" android:duration="3000" />  
    <item android:drawable="@drawable/f1" android:duration="5000" />  
    <item android:drawable="@drawable/f2" android:duration="7000" />  
</animation-list>

activity:

public class FrameActivity extends Activity{
    private ImageView image;  
    
    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.frame);  
        image = (ImageView) findViewById(R.id.frame_image);  
          
        image.setBackgroundResource(R.drawable.frame);  
        AnimationDrawable anim = (AnimationDrawable) image.getBackground();  
        anim.start();  
    }  
}

 

 

二:Tween Animation:(补间动画)

Animation的4种动画效果,分别为:移动TranslateAnimation/旋转RotateAnimation/淡入淡出AlphaAnimation/缩放ScaleAnimation

1:移动TranslateAnimation

首先是xml文件设置:

<RelativeLayout
            android:id="@+id/capture_crop_view"
            android:layout_width="300dp"
            android:layout_height="300dp"
            android:layout_below="@id/capture_mask_top"
            android:layout_centerHorizontal="true"
            android:background="@drawable/qr_code_bg" >

            <ImageView
                android:id="@+id/capture_scan_line"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_marginBottom="5dp"
                android:layout_marginTop="5dp"
                android:src="@drawable/scan_line" />
        </RelativeLayout>

图片分别为:

qr_code_bg:

scan_line:

 

代码:

scanLine = (ImageView) findViewById(R.id.capture_scan_line);
        TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT,
                0.9f);
        animation.setDuration(4500);   //从最上面到最下面持续4.5s
        animation.setRepeatCount(-1);  //从上到下循环次数,这里设置的是动画重复执行的次数,而不是动画执行的次数。故动画执行的次数为动画重复执行的次数加1
                       //Android系统默认每个动画仅执行一次,通过该方法可以设置动画执行多次。 animation.setRepeatMode(Animation.RESTART); scanLine.startAnimation(animation);

 

解析:

TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)

TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int toYType, float toYValue)

参数说明: 

float fromXDelta:这个参数表示动画开始的点离当前View X坐标上的差值;

float toXDelta, 这个参数表示动画结束的点离当前View X坐标上的差值;

float fromYDelta, 这个参数表示动画开始的点离当前View Y坐标上的差值;

float toYDelta这个参数表示动画开始的点离当前View Y坐标上的差值;

4个参数确定移动的起点和终点

 

fromXType:x轴(Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_PARENT);

Animation.RELATIVE_TO_SELF(相对于自身)、Animation.RELATIVE_TO_PARENT(相对于父控件(容器)

fromXValue:第二个参数是第一个参数类型的起始值;

toXType,toXValue:第三个参数与第四个参数是x轴方向的终点参照与对应值;

8个参数也是确定移动的起点和终点

转载于:https://www.cnblogs.com/wnpp/p/7821108.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值