如何在Android中对ImageView进行缩放

6

我在main.XML中声明了一个ImageView。我想对它进行缩放。在Android中应该如何实现?


https://dev59.com/VErSa4cB1Zd3GeqPae5e https://dev59.com/VErSa4cB1Zd3GeqPae5e - ArK
1个回答

2
在这里获取它的链接
 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;
    }
    }

3
我有一个在Layout中的图片,我会使用findViewById()获取该ImageView的引用,并想要动态地对其进行缩放。假设它位于垂直LinearLayout中,下面还有其他一些小部件。在Activity中如何实现动态缩放? - Android_programmer_camera

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接