簡體   English   中英

如何在Android中向右,向左,向上和向下移動縮放圖像?

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

我正在屏幕上上傳圖像。 那里我有一個放大按鈕。 我已經完成了放大和縮小功能。 它的工作正常。 我需要的是,我想完全拖動並查看圖像。 但是現在發生的是,圖像沒有移動。 我這里有4個按鈕。 LeftButton,RightButton,TopButton和BottomButton。 如果單擊“ LeftButton”,則圖像應向左移動。 同樣,所有其他功能。 我真的不知道,我需要在按鈕單擊內寫些什么。 有人可以為此指導我嗎? 任何幫助將非常感激..

這是我的代碼:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM