xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   >


            android:id="@+id/textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:drawableTop="@drawable/ic_launcher"
        android:text="@string/hello_world" />







package com.example.viewcsc;



import android.support.v7.app.ActionBarActivity;
import android.annotation.SuppressLint;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.TextView;


@SuppressLint("NewApi")
public class MainActivity extends ActionBarActivity {
private TextView textview;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textview=(TextView) findViewById(R.id.textview);
textview.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
setClickZoomEffect(arg0);
}
});

}


public  void setClickZoomEffect(final View view) {  
       if (view != null) {  
           view.setOnTouchListener(new OnTouchListener() {  
               boolean cancelled;  
               Rect rect = new Rect();  
 
               @Override  
               public boolean onTouch(View v, MotionEvent event) {  
                   switch (event.getAction()) {  
                   case MotionEvent.ACTION_DOWN:  
                       scaleTo(v, 1.2f);  
                       break;  
                   case MotionEvent.ACTION_MOVE:  
                       if (rect.isEmpty()) {  
                           v.getDrawingRect(rect);  
                       }  
                       if (!rect.contains((int) event.getX(), (int) event.getY())) {  
                           scaleTo(v, 1);  
                           cancelled = true;  
                       }  
                       break;  
                   case MotionEvent.ACTION_UP:  
                   case MotionEvent.ACTION_CANCEL: {  
                       if (!cancelled) {  
                           scaleTo(v, 1);  
                       } else {  
                           cancelled = false;  
                       }  
                       break;  
                   }  
                   }  
                   return false;  
               }  
           });  
       }
}
 
 
 public static void scaleTo(View v, float scale) {  
       if (Build.VERSION.SDK_INT >= 11) {  
           v.setScaleX(scale);  
           v.setScaleY(scale);  
       } else {  
           float oldScale = 1;  
           if (v.getTag(Integer.MIN_VALUE) != null) {  
               oldScale = (Float) v.getTag(Integer.MIN_VALUE);  
           }  
            LayoutParams params = v.getLayoutParams();  
           params.width = (int) ((params.width / oldScale) * scale);  
           params.height = (int) ((params.height / oldScale) * scale);  
           v.setTag(Integer.MIN_VALUE, scale);  
       }  
 }
}

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. android 窗口式activity
  2. Android简易注解View(java反射实现)
  3. Android中shape使用
  4. android makefile(android.mk)分析(转)
  5. Android平板开发注意点
  6. Android四款系统架构工具
  7. Android书籍分享
  8. Android中图片占用内存的计算
  9. Android中的几种网络请求方式详解
  10. android中的sqlite数据库加密