为什么我的 Android 应用程序运行速度变慢?

发布于 2024-10-03 07:31:27 字数 307 浏览 3 评论 0原文

我正在使用此代码显示来自互联网的多个图像

ImageView iv = new ImageView;
URL url = new URL(address);
InputStream content = (InputStream)url.getContent();
Drawable d = Drawable.createFromStream(content , "src"); 
iv.setImageDrawable(d)

,但应用程序运行速度变慢,为什么? 互联网连接是原因吗???或者因为我输入了几个输入流来显示每个图像???

I'm using this code to display severl images from the internet

ImageView iv = new ImageView;
URL url = new URL(address);
InputStream content = (InputStream)url.getContent();
Drawable d = Drawable.createFromStream(content , "src"); 
iv.setImageDrawable(d)

but the application became slow in running why ??
does the internet connection is the reason ??? or because i input several input stream to display each image???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

复古式 2024-10-10 07:31:27

您应该使用 AsyncTask 或使用单独的线程异步创建 InputStream 和 Drawable.createFromStream(...) ,然后在完成后使用 Handler 更新 ImageView 。 AsyncTask 是首选。

http://developer.android.com/reference/android/os/AsyncTask.html

You should create the InputStream and Drawable.createFromStream(...) asynchronously, either using an AsyncTask or using a separate thread and then update the ImageView using a Handler once they are complete. AsyncTask is prefereable.

http://developer.android.com/reference/android/os/AsyncTask.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文