当前位置:操作系统 > 安卓/Android >>

android实现播放器反射性动画效果

mainActivity:


[java]
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); 
         &n

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,