点击按钮 按钮缩放动画:
16lz
2021-01-26
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);
更多相关文章
- runOnUiThread()方法
- Android进阶(六)文件读操作
- 【Android(安卓)UI】案例03滑动切换效果的实现(ViewPager)
- Android学习笔记之动画效果Animation
- ImageButton的使用,如何设置背景图占满整个ImageButton
- 自定义ViewGroup实现瀑布流效果
- 14天学会安卓开发(第九天)ContentProvider与BroadcastReceiver
- Android(安卓)PopupWindow 仿微信弹出效果
- Android悬浮按钮点击返回顶部FloatingActionButton