Android 从web中线性布局背景和图像
我必须从互联网上提取图像,并将其作为线性布局的背景-这可能吗?我还没有看到任何合适的方法。只需使用Android 从web中线性布局背景和图像,android,Android,我必须从互联网上提取图像,并将其作为线性布局的背景-这可能吗?我还没有看到任何合适的方法。只需使用位图工厂加载图像(如果需要,请调整其大小),使用位图可绘制,并使用LinearLayout.setBackgroundDrawable()将图像视图设置为LinearLayout的背景即可: <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent"> <
位图工厂加载图像(如果需要,请调整其大小),使用位图可绘制
,并使用LinearLayout.setBackgroundDrawable()
将图像视图设置为LinearLayout的背景即可:
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="@+id/myimageview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
希望这有帮助。另外,请看这个(我从中获得了图像下载代码)。当然
只需获取图像的输入流:
InputStream is = (InputStream) new URL(url).getContent();
从流中获取可绘制图形:
Drawable d = Drawable.createFromStream(is, "src name");
然后将LinearLayout背景设置为可绘制:
linearLayout.setBackgroundDrawable(d);
这实际上是直接从流中设置图像。您可能希望使用ASyncTask在后台拉下绘图表,然后进行设置:
您可能还想研究惰性加载程序:
linearLayout.setBackgroundDrawable(d);