属性动画_展开菜单栏
来源:互联网 发布:mac怎么玩手游模拟器 编辑:程序博客网 时间:2024/05/22 13:41
public class MainActivity extends Activity implements View.OnClickListener{ private int imageRes[] = new int[]{ R.id.iv_a, R.id.iv_b, R.id.iv_c, R.id.iv_d, R.id.iv_e }; private boolean isShow; private MediaPlayer mMediaPlayer; private List<ImageView> imageViewList = new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.content_main); //创建MediaPlayer来播放声音 mMediaPlayer = MediaPlayer.create(this,R.raw.voice_pink05); for(int i = 0;i < imageRes.length;i++){ ImageView imageView = (ImageView) findViewById(imageRes[i]); imageView.setOnClickListener(this); imageViewList.add(imageView); } } @Override public void onClick(View v) { switch(v.getId()) { case R.id.iv_a: if(!isShow){ startAnim(); isShow = true; } else { closeAnim(); isShow = false; } break; default: Toast.makeText(MainActivity.this,v.getId()+"",Toast.LENGTH_SHORT).show();; break; } } /** * 关闭动画 */ private void closeAnim() { btnReverseRotate(); for (int i = 1; i < imageViewList.size(); i++) { ObjectAnimator anim = ObjectAnimator.ofFloat(imageViewList.get(i), "translationX",-i*100,0F); anim.setDuration(500); anim.setStartDelay(200); anim.setInterpolator(new DecelerateInterpolator()); anim.start(); } } /** * 按钮正向旋转 */ private void btnPositiveRotate(){ RotateAnimation mRotateAnimation = new RotateAnimation(0F,45F,50,50); mRotateAnimation.setFillAfter(true); mRotateAnimation.setDuration(500); imageViewList.get(0).startAnimation(mRotateAnimation); } /** * 按钮反向旋转 */ private void btnReverseRotate(){ RotateAnimation mRotateAnimation = new RotateAnimation(45F,0F,50,50); mRotateAnimation.setFillAfter(true); mRotateAnimation.setDuration(500); imageViewList.get(0).startAnimation(mRotateAnimation); } /** * 单击按钮播放声音 */ private void playSound() { mMediaPlayer.start(); } /** * 菜单展开动画 */ private void startAnim() { playSound(); btnPositiveRotate(); for (int i = 1; i < imageViewList.size(); i++) { ObjectAnimator anim = ObjectAnimator.ofFloat( imageViewList.get(i),"translationX",0F,-i * 100); anim.setDuration(500); anim.setStartDelay(200); anim.setInterpolator(new BounceInterpolator()); anim.start(); } } @Override protected void onDestroy() { super.onDestroy(); mMediaPlayer.release();//释放资源 }}
activity_main.xml布局:
<?xml version="1.0" encoding="utf-8"?><android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:context="co.huiqu.animationtest.MainActivity"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.AppBarLayout> <include layout="@layout/content_main" /> <android.support.design.widget.FloatingActionButton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" android:src="@android:drawable/ic_dialog_email" /></android.support.design.widget.CoordinatorLayout>
content_main.xml 布局:
<?xml version="1.0" encoding="utf-8"?><LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" xmlns:android="http://schemas.android.com/apk/res/android"> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="bottom|right" > <ImageView android:id="@+id/iv_b" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/b" android:layout_gravity="bottom|center_horizontal" android:layout_marginLeft="100dp" /> <ImageView android:id="@+id/iv_c" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/c" android:layout_gravity="bottom|center_horizontal" android:layout_marginLeft="100dp" /> <ImageView android:id="@+id/iv_d" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/d" android:layout_gravity="bottom|center_horizontal" android:layout_marginLeft="100dp" /> <ImageView android:id="@+id/iv_e" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/e" android:layout_gravity="bottom|center_horizontal" android:layout_marginLeft="100dp" /> <ImageView android:id="@+id/iv_a" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/a" android:layout_gravity="bottom|center_horizontal" android:layout_marginLeft="100dp" /> </FrameLayout></LinearLayout>
阅读全文
0 0
- 属性动画_展开菜单栏
- 展开拉伸动画---属性动画
- 菜单栏展开
- android动画_属性动画
- 属性动画_
- Circular Reveal圆形展开缩放属性动画
- 展开与折叠菜单栏
- 菜单栏点击展开
- 255_属性动画解析
- 259_属性动画监听
- 383_抖动属性动画
- 属性动画_点赞
- android--(动画2_属性动画)
- 关于左侧菜单栏,点击二级菜单栏展开
- Android属性动画——实现布局的下拉展开
- 属性动画的研究——多级菜单展开
- Android 布局平铺展开效果的属性动画
- 属性动画实现扇形圆形展开图效果
- 浅谈移动优先的跨终端Web 解决方案
- android studio 打包jar 及混淆
- Phthon自定义模块并导入
- CodeForces 588A. Duff and Meat
- MySQL 深入理解索引B+树存储 (二)
- 属性动画_展开菜单栏
- 初探nginx(搭建)
- session的removeAttribute()和invalidate()的区别
- NVMe和AHCI模式的区别
- 除了iPhone,谷歌还要把AI塞进Photo和厨房
- java以及javaweb开发组件,开发环境和开发工具安装配置(一:java环境--最简单的方式)
- GCOV+LCOV 代码调试和覆盖率统计工具
- 列出连通集(25 分)(深搜广搜)
- HDU