从url设置imageview图像
问题描述:
好吧我已经花了几个小时尝试弄清楚这个问题,大多数解决方案都不起作用,那些做了工作的解决方案使得图像的高度和宽度比例保持不变,我想要的是能够从URL设置imageview图像,并使宽度match_parent和高度175dp。请有人帮助我!从url设置imageview图像
答
使用下面的代码
<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) {
}
}
http://stackoverflow.com/questions/17120230/android-set-imageview-to-url/17120523#17120523。检查这可能有所帮助 – Raghunandan