我試圖用封閉樣本的Chris Banes的PhotoView庫。我對樣本進行了一些更改以從URL(在Internet上)加載圖像,而不是從可繪製的樣本加載。這裏是代碼:如何在PhotoView中加載URL圖像
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");
}
問題是圖像沒有加載然後,只是返回一個空白頁。奇怪的事情發生時,我嘗試了一些捏縮放行動,圖像被加載,並正常工作。任何人有建議?謝謝。
嗨,謝謝你的建議。但是,它只是從setimageDrawable切換到setimagebitmap。問題仍然存在。或者我不明白你的要點,如果有的話請更多地解釋我。謝謝 –