mainActivity:
package smalt.play.show;import android.app.Activity;import android.os.Bundle;import android.os.Handler;import android.view.View;import android.view.View.OnClickListener;import android.view.animation.Animation;import android.view.animation.Animation.AnimationListener;import android.view.animation.AnimationUtils;import android.widget.ImageView;public class Splayer2Activity extends Activity { ImageView ivImage; ImageView ivPlay; ImageView ivStop; ImageView ivPre; ImageView ivNext; ImageView ivShuffer; ImageView ivRepeat; Animation playAnim;// 播放按鈕動畫 Animation stopAnim;// 播放按鈕動畫 Animation preAnim;// 播放按鈕動畫 Animation nextAnim;// 播放按鈕動畫 Animation shufferAnim;// 播放按鈕動畫 Animation repeatAnim;// 播放按鈕動畫 void initView() { // 初始化 ivImage = (ImageView) findViewById(R.id.player_image); ivPlay = (ImageView) findViewById(R.id.player_play); ivStop = (ImageView) findViewById(R.id.player_stop); ivNext = (ImageView) findViewById(R.id.player_next); ivPre = (ImageView) findViewById(R.id.player_pre); ivRepeat = (ImageView) findViewById(R.id.player_repeat); ivShuffer = (ImageView) findViewById(R.id.player_shuffle); } void initData() { // 實現動畫 demoAnim(); } void initListener() { // 監聽器 playAnim.setAnimationListener(new AnimationListener() { public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub } public void onAnimationRepeat(Animation animation) { // TODO Auto-generated method stub } public void onAnimationEnd(Animation animation) { // 動畫進行完后隱藏控件 ivPlay.setVisibility(View.GONE); ivStop.setVisibility(View.GONE); ivPre.setVisibility(View.GONE); ivNext.setVisibility(View.GONE); ivRepeat.setVisibility(View.GONE); ivShuffer.setVisibility(View.GONE); } }); ivImage.setOnClickListener(new OnClickListener() { public void onClick(View v) { // 點擊專輯封面顯示控件 ivPlay.setVisibility(View.VISIBLE); ivStop.setVisibility(View.VISIBLE); ivPre.setVisibility(View.VISIBLE); ivNext.setVisibility(View.VISIBLE); ivRepeat.setVisibility(View.VISIBLE); ivShuffer.setVisibility(View.VISIBLE); } }); } void demoAnim() { // 測試動畫 playAnim = AnimationUtils.loadAnimation(this, R.anim.play_out); stopAnim = AnimationUtils.loadAnimation(this, R.anim.stop_out); preAnim = AnimationUtils.loadAnimation(this, R.anim.pre_out); nextAnim = AnimationUtils.loadAnimation(this, R.anim.next_out); shufferAnim = AnimationUtils.loadAnimation(this, R.anim.shuffer_out); repeatAnim = AnimationUtils.loadAnimation(this, R.anim.repeat_out); Handler mHandler = new Handler(); mHandler.postDelayed(new Runnable() { public void run() { ivPlay.startAnimation(playAnim); ivStop.startAnimation(stopAnim); ivPre.startAnimation(preAnim); ivNext.startAnimation(nextAnim); ivRepeat.startAnimation(repeatAnim); ivShuffer.startAnimation(shufferAnim); } }, 2000); } /** Called when the activity is first created. */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); initView(); initData(); initListener(); }}mainXML:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <RelativeLayout android:layout_width="300dp" android:layout_height="300dp" android:layout_centerInParent="true" > <!-- 專輯圖片 --> <ImageView android:id="@+id/player_image" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_centerInParent="true" android:src="@drawable/player_image" android:text="專輯" /> <!-- 播放 --> <ImageView android:id="@+id/player_play" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:paddingTop="10dp" android:src="@drawable/player_play_light" /> <!-- 停止 --> <ImageView android:id="@+id/player_stop" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:paddingBottom="10dp" android:src="@drawable/player_stop_light" /> <!-- 上一曲 --> <ImageView android:id="@+id/player_pre" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:paddingLeft="10dp" android:src="@drawable/player_prev_light" /> <!-- 下一曲 --> <ImageView android:id="@+id/player_next" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:paddingRight="10dp" android:src="@drawable/player_next_light" /> <!-- 右上隨機 --> <ImageView android:id="@+id/player_shuffle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:paddingRight="10dp" android:paddingTop="10dp" android:src="@drawable/player_shuffle_off" /> <!-- 左上順序播放 --> <ImageView android:id="@+id/player_repeat" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:paddingLeft="10dp" android:paddingTop="10dp" android:src="@drawable/player_repeat_off" /> </RelativeLayout></RelativeLayout>动画效果类似,只贴一个实例:
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" > <alpha android:duration="2500" android:fromAlpha="1.0" android:toAlpha="0.0" /> <translate android:duration="2500" android:fromXDelta="0%p" android:fromYDelta="0%p" android:toXDelta="-800%p" android:toYDelta="0%p" /> <!-- <scale android:duration="3000" android:fillAfter="true" android:fromXScale="0" android:fromYScale="0" android:toXScale="1.0" android:toYScale="1.0" /> --></set>效果:所有控件向中心收缩滑动后消失,点击专辑封面重新显示