如何在android中模拟放大或缩小事件

发布于 2024-11-15 09:15:28 字数 116 浏览 2 评论 0原文

如何在android中模拟放大和缩小事件?它需要存在于服务中并在任何 Android AP 中启动。 例如:在图像相关的 AP 和图像中实现放大和缩小事件。当服务启动放大或缩小事件时,图像将执行其操作。非常感谢。

How can I simulate the zoom in and zoom out event in android? It need to be existed in service and launch in any android AP.
Ex: in an Image-relative AP and image implement zoom in and out event. When the service launch a zoom in or out event, the image will do what it do. Thank a lot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔戏命师 2024-11-22 09:15:28

放大和缩小图像非常容易。看看这里
使用向上和向下箭头键,您可以放大和缩小图像。

zooming.java

import android.app.Activity;
import android.os.Bundle;

public class zooming extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(new Zoom(this));
    }
}

Zoom.java

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.view.KeyEvent;
import android.view.View;

public class Zoom extends View {
        private Drawable image;
        private int zoomControler=20;
        public Zoom(Context context)
        {
                super(context);
                image=context.getResources().getDrawable(R.drawable.icon);
                setFocusable(true);

        }
        @Override
        protected void onDraw(Canvas canvas) {
                // TODO Auto-generated method stub
                super.onDraw(canvas);
        //here u can control the width and height of the images........ this line is very important
        image.setBounds((getWidth()/2)-zoomControler, (getHeight()/2)-zoomControler, (getWidth()/2)+zoomControler, (getHeight()/2)+zoomControler);
                image.draw(canvas);
        }
        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {

                if(keyCode==KeyEvent.KEYCODE_DPAD_UP)// zoom in
                        zoomControler+=10;
                if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN) // zoom out
                        zoomControler-=10;
                if(zoomControler<10)
                        zoomControler=10;

                invalidate();
                return true;
        }
}

it is very easy to Zoom in and zoom out Images. take a look here
using UP and Down Arrow keys , u can zoom in and zoom out the images.

zooming.java

import android.app.Activity;
import android.os.Bundle;

public class zooming extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(new Zoom(this));
    }
}

Zoom.java

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.view.KeyEvent;
import android.view.View;

public class Zoom extends View {
        private Drawable image;
        private int zoomControler=20;
        public Zoom(Context context)
        {
                super(context);
                image=context.getResources().getDrawable(R.drawable.icon);
                setFocusable(true);

        }
        @Override
        protected void onDraw(Canvas canvas) {
                // TODO Auto-generated method stub
                super.onDraw(canvas);
        //here u can control the width and height of the images........ this line is very important
        image.setBounds((getWidth()/2)-zoomControler, (getHeight()/2)-zoomControler, (getWidth()/2)+zoomControler, (getHeight()/2)+zoomControler);
                image.draw(canvas);
        }
        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {

                if(keyCode==KeyEvent.KEYCODE_DPAD_UP)// zoom in
                        zoomControler+=10;
                if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN) // zoom out
                        zoomControler-=10;
                if(zoomControler<10)
                        zoomControler=10;

                invalidate();
                return true;
        }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文