图片,文字等控件的上下抖动或左右晃动

<span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: rgb(255, 255, 255);">在这里我以一个图片作为例子,实现上下抖动和左右晃动的特效,用得到的小伙伴可以借鉴~</span>

cycle.xml

<?xml version="1.0" encoding="utf-8"?>
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android" 
android:cycles="9" />//晃动频率


上下抖动布局

可以写在anim文件夹中!

shake_y.xml

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="2500"
    android:fromYDelta="0"
    android:interpolator="@anim/cycle"
    android:toYDelta="10" >

</translate>

左右抖动布局

shake_x.xml

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000"
    android:fromYDelta="0"
    android:interpolator="@anim/cycle"
    android:toYDelta="10" >

</translate>

代码调用:

//实例化一个图片
ImageView location=new ImageView(context);
//开启动画
Animation shakeAnim = AnimationUtils.loadAnimation(context,
				R.anim.shake_y);
		location.startAnimation(shakeAnim);



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值