android笔记——点击按钮放大
来源:互联网 发布:炫酷团队网站源码 编辑:程序博客网 时间:2024/04/29 09:44
package com.example.button;import android.os.Bundle;import android.animation.AnimatorSet;import android.animation.ObjectAnimator;import android.app.Activity;import android.view.MotionEvent;import android.view.View;import android.widget.Button;public class MainActivity extends Activity { private Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button = (Button) findViewById(R.id.button); button.setOnTouchListener(new Button.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { //点击按钮未松开时按钮放大 blow_up(button); } else if (event.getAction() == MotionEvent.ACTION_UP) { //点击按钮松开后按钮缩小 narrow(button); } return false; } }); } //放大按钮动画 private void blow_up(View v) { float[] vaules = new float[] { 1.0f, 1.1f, 1.2f, 1.3f, 1.4f, 1.5f}; AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(v, "scaleX", vaules), ObjectAnimator.ofFloat(v, "scaleY", vaules)); set.setDuration(150); set.start(); } //缩小按钮动画 private void narrow(View v) { float[] vaules = new float[] { 1.5f, 1.4f, 1.3f, 1.2f, 1.1f, 1.0f}; AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(v, "scaleX", vaules), ObjectAnimator.ofFloat(v, "scaleY", vaules)); set.setDuration(150); set.start(); }}
布局文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" tools:context=".MainActivity" > <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="点我放大" /></RelativeLayout>
Animation介绍
http://www.cnblogs.com/shaweng/archive/2012/06/08/2541258.html
0 0
- android笔记——点击按钮放大
- 【Android】OnTouchListener的简单使用,按钮点击放大与缩小
- cocos2dx --- 按钮点击居中放大
- cocos2dx --- 按钮点击居中放大
- 点击按钮图片放大查看
- android 图片点击放大
- Android 点击图片放大
- Android学习笔记(3)——按钮点击注册事件的四种写法
- iOS 如何放大按钮点击热区
- 向右移动放大后点击按钮可以继续放大
- Android view点击放大缩小
- Android点击缩略图,放大至全图
- Android图片点击放大等
- Android 图片放大,缩小,点击还原,double点击放大
- Android——点击对话框上按钮不关闭对话框
- Android——点击对话框上按钮不关闭对话框
- Android——点击对话框上按钮不关闭对话框
- Android——点击对话框上按钮不关闭对话框
- 嵌入式linux之poll机制
- 收藏网站6
- 全志A20平台增加USB挂载点
- Andriod电子词典查询功能的实现
- runOnUiThread
- android笔记——点击按钮放大
- 2012年5月SAT香港真题解析
- 集合中取出列名相同的,并把其他列的值合并成数组
- 收藏网站8
- @Scope("prototype")
- unity profiler and optimize and compress android Package
- linux shell 脚本自动从配置远程ftp服务上下载更新文件
- 深入Java核心 Java内存分配原理精讲
- StringBuffer的妙用