<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="click1"
android:text="透明" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="click2"
android:text="缩放" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="click3"
android:text="旋转" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="click4"
android:text="平移" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="click5"
android:text="组合" />
</LinearLayout>
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher" />
</LinearLayout>
=================================================================================================================================
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="1.0"
android:toAlpha="0.2"
android:fillAfter="true"
android:duration="2000">
</alpha>
-----------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="2000" >
</rotate>
-----------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="0.2"
android:toXScale="1.0"
android:fromYScale="0.2"
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="2000" >
</scale>
-----------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0%p"
android:toXDelta="50%p"
android:fromYDelta="0%p"
android:toYDelta="0%p"
android:duration="2000"
android:repeatCount="2"
android:repeatMode="reverse" >
</translate>
-----------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="2000" android:fromXDelta="0%p" android:fromYDelta="0%p" android:repeatCount="2" android:repeatMode="reverse" android:toXDelta="50%p" android:toYDelta="0%p" > </translate> <scale android:duration="2000" android:fromXScale="0.2" android:fromYScale="0.2" android:pivotX="50%" android:pivotY="50%" android:repeatCount="2" android:repeatMode="reverse" android:toXScale="1.0" android:toYScale="1.0" > </scale> </set>
=================================================================================================================================
public class MainActivity extends Activity {
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView) findViewById(R.id.image);
}
/**
* 透明度
*
* @param view
*/
public void click1(View view) {
Animation animation = AnimationUtils.loadAnimation(this,R.anim.alpha_anim);
imageView.startAnimation(animation);
}
/**
* 缩放
*
* @param view
*/
public void click2(View view) {
Animation animation = AnimationUtils.loadAnimation(this,R.anim.scale_anim);
imageView.startAnimation(animation);
}
/**
* 旋转
*
* @param view
*/
public void click3(View view) {
Animation animation = AnimationUtils.loadAnimation(this,R.anim.rotate_anim);
imageView.startAnimation(animation);
}
/**
* 平移
*
* @param view
*/
public void click4(View view) {
Animation animation = AnimationUtils.loadAnimation(this,R.anim.translate_anim);
imageView.startAnimation(animation);
}
/**
* 组合
*
* @param view
*/
public void click5(View view) {
Animation animation = AnimationUtils.loadAnimation(this,R.anim.set_anim);
imageView.startAnimation(animation);
}
}