如何增加或减少android中按钮上的图像大小?

时间:2011-06-21 04:22:57

标签: android image button

我制作了一个Android应用程序,其中我的图像很少。我已经实现了触摸功能,用户可以通过触摸来回移动。现在我想在按钮点击时缩放图像。任何建议或教程如何放大和缩小按钮点击将有所帮助。

2 个答案:

答案 0 :(得分:2)

答案 1 :(得分:2)

检查以下链接以缩放图像

http://vinnysoft.blogspot.com/2009/08/zooming-imageview.html

http://blogs.sonyericsson.com/wp/2010/05/18/android-one-finger-zoom-tutorial-part-1/

public class Zoom extends View {
    private Drawable image;
    private int zoomControler=200;
    public Zoom(Context context)
    {
    super(context);
    image=context.getResources().getDrawable(R.drawable.gallery_photo_1);
    setFocusable(true);
    }
    @Override
    protected void onDraw(Canvas canvas) {
    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;
    }
    }

由于 迪帕克