简体   繁体   English

如何在Android中向右,向左,向上和向下移动缩放图像?

[英]How to move right, left,top and bottom for zoom Image in android?

I am uploading an image in a screen. 我正在屏幕上上传图像。 There i have Zoom-in an Zoom-out buttons. 那里我有一个放大按钮。 Already I have done Zoom-in and Zoom-out functions. 我已经完成了放大和缩小功能。 Its working fine. 它的工作正常。 what I need is, I want to drag and see the Image completely. 我需要的是,我想完全拖动并查看图像。 But what happens now is, the image is not moving. 但是现在发生的是,图像没有移动。 I have 4 butons here. 我这里有4个按钮。 LeftButton,RightButton,TopButton and BottomButton. LeftButton,RightButton,TopButton和BottomButton。 If I click 'LeftButton', Image should move left side. 如果单击“ LeftButton”,则图像应向左移动。 Similarly all the other functions. 同样,所有其他功能。 I am not really having idea, what I need to write inside the button clicks. 我真的不知道,我需要在按钮单击内写些什么。 Could anyone please guide me for this? 有人可以为此指导我吗? Any help would be really appreciated.. 任何帮助将非常感激..

Here is my code: 这是我的代码:

selectedPicture is my ImageLayout selectedPicture是我的ImageLayout

case R.id.zoomInCtrl:
    float x = selectedPicture.getScaleX();
    float y = selectedPicture.getScaleY();

    selectedPicture.setScaleX((float) (x + 0.5));
    selectedPicture.setScaleY((float) (y + 0.5));

    return true;
case R.id.zoomOutCtrl:
    x = selectedPicture.getScaleX();
    y = selectedPicture.getScaleY();

    selectedPicture.setScaleX((float) (x - 0.5));
    selectedPicture.setScaleY((float) (y - 0.5));

    return true;
case R.id.leftCtrl:
    /* code for move left */
    return true;
case R.id.rightCtrl:
    /* code for move right */
    return true;
case R.id.topCtrl:
    /* code for move top */
    return true;
case R.id.bottomCtrl:
    /* code for move bottom */
    return true;

我认为View的setTranslationX和setTranslationY方法最适合您想要的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在android的左上角和右下角创建圆角半径? - How to create corner radius in top left and bottom right in android? 获取图像的极右,左,上,下位置-Itext - Get the Extreme right , left,top,bottom position of an image - Itext 如何使用坐标显示带有许多按钮的图像; 左,上,右和下 - How to display an image with many buttons by using coordinates; left,top,right and bottom Android 在 Canvas 上获得 Bitmap 矩形(左、上、右、下) - Android get Bitmap Rect (left, top, right, bottom) on a Canvas 如何左右移动背景图像? - how to move background image left to right? 如何从上到下然后从左到右填充 GridLayout? - How to fill a GridLayout top-to-bottom and then left-to-right? 如何从上到下,从左到右给出JLabel定位 - How to give the JLabel Positioning from top to bottom and left to right 您好,我想将卫星菜单从屏幕的右上角移到屏幕的左下角 - hello,I would like to move my satellite menu from top right corner to the bottom left corner of the screen 在boxlayout中是否有“从上到下”和“从右到左”? - Is there any 'top to bottom' and 'right to left' in boxlayout? 左上/右下网格的算法? - Algorithm for a top left/bottom right grid?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM