我正在尝试使用带有封闭样本的 Chris Banes 的 PhotoView 库。我对 sample 进行了一些更改,以从 URL(在 Internet 上)加载图像,而不是从 drawable as sample 加载图像。这是代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mImageView = (ImageView) findViewById(R.id.iv_photo);
mCurrMatrixTv = (TextView) findViewById(R.id.tv_current_matrix);
//here's the method to load URL image from URL
new LoadImage().execute();
mAttacher = new PhotoViewAttacher(mImageView);
}
private class LoadImage extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
// Simulates a background job.
try {
mImageView.setImageDrawable(grabImageFromUrl(image_url));
} catch (Exception e) {
e.getStackTrace().toString();
}
return null;
}
}
private Drawable grabImageFromUrl(String url) throws Exception {
return Drawable.createFromStream((InputStream)new URL(url).getContent(), "src");
}
问题是图像没有加载,只是返回一个空白页。当我尝试一些捏缩放动作时,奇怪的事情发生了,图像被加载并正常工作。有人有建议吗?谢谢。