我正在使用库在ImageView中放大和缩小。我正在使用PhotoAttacher。当我点击ImageView时,首先将ImageView加载到全屏(在对话框中),这很好。但是在全屏模式下加载时,缩放功能已经发生。当我第一次单击ImageView时,如何避免缩放。代码如下:
image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Dialog nagDialog = new Dialog(DetailView.this,
android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
nagDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
nagDialog.setCancelable(false);
nagDialog.setContentView(R.layout.preview_image);
Button btnClose = (Button) nagDialog
.findViewById(R.id.btnIvClose);
ivPreview = (ImageView) nagDialog
.findViewById(R.id.iv_preview_image);
// Loading image from url in ImageView
Picasso.with(getApplicationContext()).load(path)
.placeholder(R.drawable.loading).into(ivPreview);
// Here definition of zoom function
PhotoViewAttacher mAttacher = new PhotoViewAttacher(ivPreview);
mAttacher.canZoom();
btnClose.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
nagDialog.dismiss();
}
});
nagDialog.show();
}
});
奇怪的是,当我关闭预览并再次点击图像视图时,它不会先放大。
答案 0 :(得分:0)
成功加载图像后,您可以实施PhotoViewAttacher。
添加回调以了解请求是否成功完成。
示例代码:
Picasso.with(getApplicationContext()).load(path)
.placeholder(R.drawable.loading).into(ivPreview, new Callback(){
@Override
public void onSuccess()
{
Log.d("Test picasso", "image loaded");
PhotoViewAttacher mAttacher = new PhotoViewAttacher(ivPreview);
mAttacher.canZoom();
}
@Override
public void onError()
{
Log.d("Test picasso", "image error");
}
});
请注意,回调参数是strong reference,会阻止您的活动或片段被垃圾回收。所以你应该调用一个相邻的Picasso.cancelRequest(android.widget.ImageView)调用来防止临时泄漏。