Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pinching zoom for text view

Tags:

android

I want to do pinching functionality (zoom in /zoom Out) for text view .

I have already refer to many tutorials but not getting any fruitful ..please help me if any one have done it or Knows how to do it ....

Can I do it also with using button as zoom in and out and/or using 2 finger pinching ?

any help would be appreciated.. thanks

not working code:

  setContentView(R.layout.main);
  mainView =(LinearLayout)findViewById(R.id.linearLayout);

  Button buttonZoomOut = (Button)findViewById(R.id.buttonZoomOut);
  Button buttonNormal = (Button)findViewById(R.id.buttonNormal);
  Button buttonZoomIn = (Button)findViewById(R.id.buttonZoomIn);

  buttonZoomOut.setOnClickListener(new View.OnClickListener() {    
   public void onClick(View v) {
    zoom(0.5f,0.5f,new PointF(0,0));    
   }
  });
  buttonNormal.setOnClickListener(new OnClickListener() {

   public void onClick(View v) {
    zoom(1f,1f,new PointF(0,0));  
   }
  });
  buttonZoomIn.setOnClickListener(new View.OnClickListener() {

   public void onClick(View v) {
    zoom(2f,2f,new PointF(0,0));   
   }
  });
 }

 /** zooming is done from here */
 public void zoom(Float scaleX,Float scaleY,PointF pivot){
  mainView.setPivotX(pivot.x);
  mainView.setPivotY(pivot.y);  
  mainView.setScaleX(scaleX);
  mainView.setScaleY(scaleY);  
 } 
like image 564
shyam Avatar asked Mar 29 '12 10:03

shyam


1 Answers

If you want to implement finger pinch, you can see this sample code given by Google developer blog.

I tried it before. It works and good for learning.

like image 189
dreamtale Avatar answered Oct 18 '22 06:10

dreamtale