1,有时候在项目开发中遇到一些按钮的点击动画,下面就写一个比较简单的按钮缩放效果

  • 首先我们的在res目录下amin文件下创建一个Xml文件夹用来设置动画的效果,
<set xmlns:android="http://schemas.android.com/apk/res/android">    <scale android:fromXScale="1.0"        android:toXScale="0.9"        android:fromYScale="1.0"        android:toYScale="0.9"        android:pivotX="50%"        android:pivotY="50%"        android:duration="100"/>set>

我们在点击事件中去应用
(延时跳转)

 Animation animation = AnimationUtils.loadAnimation(MainFirst_Acticity.this, R.anim.set_scale);                card_fragment_a_1.startAnimation(animation);                new Handler().postDelayed(new Runnable() {                    @Override                    public void run() {                        Intent intentCH = new Intent(MainFirst_Acticity.this, ChangeActivity.class);                        startActivity(intentCH);                    }                }, 300);

2,还有一种简便的写法 就是继承OnTouchListener,重写OnTouch方法:

   @Override    public boolean onTouch(View view, MotionEvent motionEvent) {        /*按下操作*/        if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {            animation = new ScaleAnimation(1.0f, 0.9f, 1.0f, 0.9f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);            animation.setDuration(100);            animation.setFillAfter(true);            view.startAnimation(animation);        }        /*抬起操作*/        if (motionEvent.getAction() == MotionEvent.ACTION_UP) {            animation = new ScaleAnimation(0.9f, 1.0f, 0.9f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);            animation.setDuration(100);            animation.setFillAfter(true);            view.startAnimation(animation);        }        return false;    }

并且按钮必须要添加这两个监听:

card_fragment_a_1.setOnClickListener(this);card_fragment_a_1.setOnTouchListener(this);

更多相关文章

  1. runOnUiThread()方法
  2. Android进阶(六)文件读操作
  3. 【Android(安卓)UI】案例03滑动切换效果的实现(ViewPager)
  4. Android学习笔记之动画效果Animation
  5. ImageButton的使用,如何设置背景图占满整个ImageButton
  6. 自定义ViewGroup实现瀑布流效果
  7. 14天学会安卓开发(第九天)ContentProvider与BroadcastReceiver
  8. Android(安卓)PopupWindow 仿微信弹出效果
  9. Android悬浮按钮点击返回顶部FloatingActionButton

随机推荐

  1. android 沉浸式状态栏的三种方法
  2. 初识android
  3. Android(安卓)系统中GPS Location Servic
  4. Android手机拍照和手机相册选取图片的工
  5. 又一处疑难杂症的折腾笔记:Android内嵌htm
  6. Google rushing out Android(安卓)4 'Ice
  7. android软件开发:横竖屏
  8. Android(安卓)webview Not allowed to lo
  9. Ubuntu 无线热点 Set Up A Wireless Hots
  10. Android(安卓)Ant打包及其环境变量配置