Android如何实现Zoom Controls功能

时间:2015-02-19 11:43:14

标签: android

我是Android新手,如何实现ZoomControls zoomIn& zoomOut fucntions ..请提供放大和缩小的代码。感谢

   private ZoomControls zoom;
   View v;

  zoom.setOnZoomInClickListener(new View.OnClickListener() {

public void onClick(View v) {
    // TODO Auto-generated method stub
    //
}

}); 
zoom.setOnZoomOutClickListener(new View.OnClickListener() {

public void onClick(View v) {
    // TODO Auto-generated method stub
    //


}
});

2 个答案:

答案 0 :(得分:0)

请按以下步骤操作 http://sampleprogramz.com/android/zoomcontrols.php

您将通过 zoomcontrols 了解如何执行此操作。

希望它会对你有所帮助。

答案 1 :(得分:0)

//Use this code for zoom in and out using buttons  
  public class MainActivity extends Activity {
    ZoomControls zoom;
    ImageView img;
        @SuppressLint("NewApi")
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    zoom = (ZoomControls)findViewById(R.id.zoomControls1);
    img = (ImageView)findViewById(R.id.imageView1);
    zoom.setOnZoomInClickListener(new View.OnClickListener() {

        @SuppressLint("NewApi")
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            float x = img.getScaleX();
            float y =img.getScaleY();
    img.setScaleX((float) (x+1));
    img.setScaleY((float) (y+1));
        }
    });
        zoom.setOnZoomOutClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                float x = img.getScaleX();
                float y =img.getScaleY();
        img.setScaleX((float) (x-1));
        img.setScaleY((float) (y-1));
            }
        });
        }
    }