04_item简单平移动画

来源:互联网 发布:网络禁书100本百度云 编辑:程序博客网 时间:2024/04/20 11:13

listviewitem动画

我们来搞一种item的动画,

大概就是点击的时候进入还有移出去的动画

我们来创建动画

TranslateAnimation animation=new

TranslateAnimation(8个参数);

8个参数

4个就是x轴的移动效果

4个就是y轴的移动效果

1.fromXType

2.fromXValue

3.toXType

4.toXValue

 

 

先来看第一个fromXType

就是类型,有三种

Animation.ABSOLUTE:绝对位置,没有定位坐标

Animation.RELATIVE_TO_SELF:相对于自身来说

Animation.RELATIVE_TO_PARENT:相对于父控件

一般都是用第二个比较多

 

 

然后是第二个fromXValue

就是从哪里开始移动

0就是从左边,1就是右边,都是整个的,没有填0.5

一半的,一半的话怎么移啊

如果是from0,to1

那就是从屏幕的左边移动到屏幕的右边

 

这里都是相对于我们这个item的左上角来说的,

以从右移动到左边就是

from0,to-1

 

后面Y方向是没有变化的,都填0

所以

right=new TranslateAnimation

(Animation.RELATIVE_TO_SELF,0

Animation.RELATIVE_TO_SELF,1

Animation.RELATIVE_TO_SELF,0

Animation.RELATIVE_TO_SELF,0);

left=new TranslateAnimation

(Animation.RELATIVE_TO_SELF,0

Animation.RELATIVE_TO_SELF,-1

Animation.RELATIVE_TO_SELF,0

Animation.RELATIVE_TO_SELF,0);

 

 

我们还要设置一下动画时间,

不然这个动画一下子就执行完了,几乎看不到效果

right.setDuration(500);

left.setDuration(500);

然后我们让View调用startAnimation()方法.

 

0 0