android 中的抖动效果(仿苹果)

本文介绍了如何在Android中创建类似苹果设备的抖动效果,包括左右和上下两种抖动动画,详细讲解了核心代码`res/anim/cycle.xml`的内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

三种抖动效果
1. 左右抖动
2. 上下抖动

核心代码:

res/anim/cycle.xml

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

res/anim/shage_x.xml

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

res/anim/shage_y.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>


3. 仿苹果长按时的抖动

res/anim/anim.xml

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="180"
    android:fromDegrees="-2"
    android:pivotX="100%"
    android:pivotY="100%"
    android:repeatCount="infinite"
    android:repeatMode="reverse"
    android:toDegrees="2" />


代码中使用方法:

				Animation shake = AnimationUtils.loadAnimation(
						ShakeDemoActivity.this, R.anim.anim);
				shake.reset();
				shake.setFillAfter(true);
				imageview.startAnimation(shake);


源码下载地址:

http://download.youkuaiyun.com/detail/liangguo03/4219580






                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值