gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 04:38:54 25 4
gpt4 key购买 nike

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

最佳答案

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

缩放.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;
}
}

关于android - 如何在android中模拟放大或缩小事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6353575/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com