【问题标题】:Set imageview image from a url从 url 设置 imageview 图像
【发布时间】:2013-06-19 16:23:37
【问题描述】:
好吧,我花了几个小时试图解决这个问题,但大多数解决方案都不起作用,起作用的解决方案使图像的高度和宽度比保持不变,我想要的是能够设置来自 URL 的 imageview 图像并使宽度 match_parent 和高度 175dp。请有人帮助我!!!
【问题讨论】:
标签:
android
image
url
imageview
【解决方案1】:
使用以下代码
<ImageView android:layout_width="match_parent"
android:layout_height="175dp"
android:scaleType="fitXY"
/>
public static void LoadImageFromWebOperations(String url,ImageView img) {
try {
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
img.setImageDrawable(d);
} catch (Exception e) {
}
}