定义Animation
Animation shake;
在Oncreate....中
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout......);
shake = AnimationUtils.loadAnimation(this, R.anim.shake);
在xml中实现滑动范围anim文件夹<shake.xml>以及<cycle_7.xml>
<translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="600" android:fromXDelta="0" android:interpolator="@anim/cycle_7" android:toXDelta="10" />
<?xml version="1.0" encoding="utf-8"?>
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android" android:cycles="7" />
首先,需要实现点击事件
public OnClickListener clickListener = new OnClickListener() {
@Override
public void onClick(View v) {
v.startAnimation(shake);
switch (v.getId()) {
这样,当你点击事件的时候,就会出现左右晃动效果