android layerlist bitmap,android – 在LayerListDrawable中更改Bitmap Drawable

在Android开发中,遇到一个挑战:如何在运行时动态改变LayerList中的Bitmap资源而不影响其尺寸。尝试使用LayerDrawable的setDrawableByLayerId方法替换drawable,但未成功。问题在于图像被缩放,可能因为LayerList的配置导致。
摘要由CSDN通过智能技术生成

这是我的LayerList的简化版本.它在项目中有一个位图以防止缩放.我想以编程方式更改此位图的drawable.有没有办法做到这一点?

android:id="@+id/item"

android:left="165dp"

android:top="245dp" >

android:id="@+id/bitmap"

android:src="@drawable/tag_de_01"

android:gravity="top|left" />

我尝试了以下但没有成功:

Resources res = getResources();

LayerDrawable layerDrawable = (LayerDrawable) res.getDrawable(R.drawable.layer_list_drawable);

Drawable newDrawable = (Drawable)res.getDrawable(R.drawable.something);

// works, but scales the image because the drawable of the item is set instead the one of the bitmap

layerDrawable.setDrawableByLayerId(R.id.item, newDrawable);

// doesn't work at all

layerDrawable.setDrawableByLayerId(R.id.bitmap, newDrawable);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值