android实现播放器反射性动画效果
来源:互联网 发布:00后网络晒怀孕照 编辑:程序博客网 时间:2024/04/28 15:44
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>
效果:所有控件向中心收缩滑动后消失,点击专辑封面重新显示
- android实现播放器反射性动画效果
- android 实现 bilili 动画播放效果
- Android动画效果实现
- android实现动画效果
- Android实现动画效果
- Android播放器菜单的显示隐藏动画效果
- Android播放器MediaPlayer实现均衡器效果
- Android序列帧播放动画(撞钟效果)
- Android:简单动画效果-淡入淡出播放
- Android逐帧动画的简单使用-语音播放效果的实现
- Android ActionSheet动画效果实现
- Android ObjectAnimator动画效果实现
- android widget 动画效果实现
- android动画实现单摆效果
- Android: 动画实现雷达效果
- android 控件动画效果实现
- Android 实现倒计时动画效果
- Android GridView实现动画效果
- Java编程中“为了性能”需做的26件事
- [转]数据库Sharding的基本思想和切分策略
- js中的静态变量
- 说一说小提琴怎样装配和调整
- 终于有点明白编译原理是讲什么的了
- android实现播放器反射性动画效果
- 高通ANDROID平台默认时间修改
- typeid详解
- 写给在伪ACM上挣扎着即将毕业的人
- [Android] SurfaceView使用实例
- java学习
- 关于宏定义的形式
- 全文指引:《大道至易》中附录摘引的全文目录
- struts2上传excel文件并解析数据插入数据库