本文介绍了捏缩放文本视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的捏功能(放大/缩小)的文本视图。

我已经指很多教程,但没有得到任何卓有成效的..please帮助  我如果任何人都做到了,或知道如何做到这一点......

我可以做到这一点也与使用按钮放大和缩小和/或使用2个手指捏?

任何帮助将是AP preciated ..  谢谢

不工作code

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

  按钮buttonZoomOut =(按钮)findViewById(R.id.buttonZoomOut);
  按钮buttonNormal =(按钮)findViewById(R.id.buttonNormal);
  按钮buttonZoomIn =(按钮)findViewById(R.id.buttonZoomIn);

  buttonZoomOut.setOnClickListener(新View.OnClickListener(){
   公共无效的onClick(视图v){
    变焦(0.5F,0.5F,新的PointF(0,0));
   }
  });
  buttonNormal.setOnClickListener(新OnClickListener(){

   公共无效的onClick(视图v){
    变焦(1F,1F,新的PointF(0,0));
   }
  });
  buttonZoomIn.setOnClickListener(新View.OnClickListener(){

   公共无效的onClick(视图v){
    变焦(2F,2F,新的PointF(0,0));
   }
  });
 }

 / **变焦从这里完成* /
 公共无效变焦(浮动的scaleX,浮动的scaleY,的PointF支点){
  mainView.setPivotX(pivot.x);
  mainView.setPivotY(pivot.y);
  mainView.setScaleX(将scaleX);
  mainView.setScaleY(的scaleY);
 }
 

解决方案

如果你想实现的手指掐,你可以看到这个的。

我以前尝试过。它的工作原理和良好的学习。

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);
 }
解决方案

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.

这篇关于捏缩放文本视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 05:10