[英]Load Image From URL into ListView
如何从URL中的imageView for List项加载图像。
I used this in getView() in ListView adapter. 我在ListView适配器中的getView()中使用了它。
Webview kWebview = new Webview(context);
kWebview.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
kWebview.setFocusable(false);
kWebview.setClickable(false);
kWebview.setLongClickable(false);
kWebview.setFocusableInTouchMode(false);
kWebview.setInitialScale(100);
kWebview.setBackgroundColor(Color.BLACK);
WebSettings kSet = kWebview.getSettings();
kSet.setLoadWithOverviewMode(false);
kSet.setLoadsImagesAutomatically(true);
kSet.setAppCacheEnabled(true);
kSet.setAppCachePath(_context.getCacheDir().toString());
kSet.setCacheMode(WebSettings.LOAD_DEFAULT);
kSet.setAllowFileAccess(true);
kSet.setDomStorageEnabled(true);
kWebview.loadUrl("http://image_url");
Webview is more smoothly load than ImageView Webview比ImageView更加平滑
Try this code: 试试这段代码:
string path = item.ImgPath;
URL url = new URL(path);
URI uri = new URI(url.Protocol, url.UserInfo, url.Host, url.Port, url.Path, url.Query, url.Ref);
url = uri.ToURL();
//convert it into bitmap
var bitmap = Android.Graphics.BitmapFactory.DecodeStream(url.OpenStream());
//set bitmap drawable
System.IO.Stream stream = url.OpenStream();
Img.SetImageBitmap(bitmap);
Try Below code : 试试以下代码:
try
{
URL img_value = null;
img_value = new URL("ImageUrl");
Bitmap mIcon1 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
Image.setImageBitmap(mIcon1);
}
catch(Exception e)
{
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.