android - 如何在片段中添加网址图像?
问题描述
我想在片段中添加 url 图像,但我无法做到这一点。
URL imageUrl = new URL("http://image10.bizrate-images.com/resize?sq=60&uid=2216744464");
public HomeFragment() throws MalformedURLException {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_home, container, false);
try {
ImageView i = (ImageView)rootView.findViewById(R.id.image);
Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(imageUrl).getContent());
i.setImageBitmap(bitmap);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return rootView;
}
它显示错误
错误:(48, 77) 错误:不兼容的类型:无法将 URL 转换为字符串
错误:任务“:app:compileDebugJavaWithJavac”执行失败。
编译失败;有关详细信息,请参阅编译器错误输出。
解决方案
推荐阅读
- python - Mongo DB聚合日期过滤器不起作用
- javascript - 当我使用 mockImplementationOnce 时,新函数没有获取父函数的 args
- swift - 如何在 OutlineView 单元格中显示鼠标悬停按钮
- c++ - 如何在下一个函数中读取外部“switch case”的状态?
- angular - 使用 Angular 和 dotNet 核心进行拖放
- qlikview - 一个字段的 Qlik Sense 总和基于其他字段的唯一值
- python - 在单个页面上处理不同的表单发布请求-Django
- python - 当一个在熊猫中有multiIndex时合并两个数据框
- c# - 起订量功能
委托和设置值 - c# - 使用 HttpUtility.HtmlDecode 或 MvcHtmlString.Create 从 HTML 字符串渲染部分视图