简体   繁体   English

如何在imageview中添加缩放效果

[英]how to add zoom effect in imageview

I want to show a image in a activity . 我想在活动中显示图像。 I successfully made it with imageview.But it has no zoom effect ie. 我用imageview成功地制作了它,但是没有缩放效果。 I can't zoom the pic. 我无法放大图片。 now how can I add this zoom efect. 现在如何添加此缩放效果。 my .xml code is : 我的.xml代码是:

 <ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="fitXY"
    android:src="@drawable/cat" />

use the lib https://github.com/chrisbanes/PhotoView 使用lib https://github.com/chrisbanes/PhotoView

In code 在代码中

ImageView mImageView;
PhotoViewAttacher mAttacher;

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

// Any implementation of ImageView can be used!
mImageView = (ImageView) findViewById(R.id.iv_photo);

// Set the Drawable displayed
Drawable bitmap = getResources().getDrawable(R.drawable.wallpaper);
mImageView.setImageDrawable(bitmap);

// Attach a PhotoViewAttacher, which takes care of all of the zooming functionality.
mAttacher = new PhotoViewAttacher(mImageView);
}


// If you later call    mImageView.setImageDrawable/setImageBitmap/setImageResource/etc then you just need to call
     attacher.update();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM