背景的LinearLayout和Web图像 [英] LinearLayout background and images from web
问题描述
我从互联网上得提取图像并应用它们作为一个的LinearLayout的背景 - 这可能吗?我还没有看到这方面的任何适当的方法呢。
I gotta extract images from internet and apply them as a LinearLayout's background - is it possible ? I haven't seen any appropriate methods for this yet.
推荐答案
当然可以。
刚刚得到的图像的InputStream:
Just get the InputStream of the image:
InputStream is = (InputStream) new URL(url).getContent();
从流获取绘制对象:
Get the Drawable from the stream:
Drawable d = Drawable.createFromStream(is, "src name");
然后设置的LinearLayout背景绘制对象:
Then set the LinearLayout Background Drawable:
linearLayout.setBackgroundDrawable(d);
这实际上是图像直接从流设置。您可能需要使用的AsyncTask拉下绘制的背景和设置算账:
http://developer.android.com/reference/android/os/AsyncTask.html
This actually sets the image directly from the stream. You may want to use an ASyncTask to pull down the drawable in the background and set it afterwards: http://developer.android.com/reference/android/os/AsyncTask.html
您可能想偷懒研究装载机,以及:
http://evancharlton.com/thoughts/lazy-loading-images-in -a-的ListView
You may want to research lazy loaders as well: http://evancharlton.com/thoughts/lazy-loading-images-in-a-listview
这篇关于背景的LinearLayout和Web图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!