gpt4 book ai didi

android - 如何通过位图交换图层列表中的图像?

转载 作者:太空宇宙 更新时间:2023-11-03 13:06:23 25 4
gpt4 key购买 nike

这是我的位图

Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(url).getContent());
//Need some code to access "dynamicItem" and exchange it with my Bitmap

这是我的图层列表(没什么了不起的)。我想用我的位图交换 dynamicItem。

<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/dynamicItem"
android:drawable="@drawable/defaultItem" />
<item>
<bitmap

android:src="@drawable/some_stuff_on_top"
android:gravity="top|left" />
</item>
</layer-list>

最佳答案

LayerDrawable 中的 setDrawableByLayerId 方法采用 (int, Drawable) 而不是 (int, Bitmap),因此首先从位图中创建一个可绘制对象

Drawable drawable = new BitmapDrawable(bitmap);
layerDrawable.setDrawableByLayerId(R.id.dynamicItem, drawable);

关于android - 如何通过位图交换图层列表中的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3864977/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com