簡體   English   中英

縮放時左右移動圖像

[英]Move Image Left & Right When it Zoomed

縮放后如何左右移動圖像? 我已經完成了圖像縮放,現在不知道要為手指移動創建哪些代碼,該代碼一旦縮放就可以編寫。

請查看我的代碼,並給我您寶貴的答復。 如果可能,請編輯我的代碼。 提前致謝。

MainActivity.java

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.ZoomControls;

public class MainActivity extends Activity {

    ImageView img;
    ZoomControls zoom;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        img = (ImageView) findViewById(R.id.imageView1);
        zoom = (ZoomControls) findViewById(R.id.zoomControls1);

        zoom.setOnZoomInClickListener(new View.OnClickListener() {

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

            int w = img.getWidth();
            int h = img.getHeight();

            RelativeLayout.LayoutParams params = 
                new RelativeLayout.LayoutParams(w + 10, h +10);
            params.addRule(RelativeLayout.CENTER_IN_PARENT);

            img.setLayoutParams(params);
        }
    });

        zoom.setOnZoomOutClickListener(new View.OnClickListener() {

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

            int w = img.getWidth();
            int h = img.getHeight();

            RelativeLayout.LayoutParams params = 
                new RelativeLayout.LayoutParams(w - 10, h -10);
            params.addRule(RelativeLayout.CENTER_IN_PARENT);

            img.setLayoutParams(params);
        }
    });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

activity_main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:src="@drawable/ic_launcher" />

<ZoomControls
    android:id="@+id/zoomControls1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="50dp" />

試試這個庫..它易於實現並且可以完美地工作

圖像縮放庫

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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