我遇到了一个问题,我的图层列表绘制有时不能完全渲染。
在我的活动的onCreate中,我已经程序化地创建了一些TextViews,在onResume中,我正在调用web服务,在获得响应后,我会相应地更新这个TextViews。
TextView tv = getView().findViewWithTag(tag);
if ((int) wt.getCustomerId() == Const.CUSTOMER_xxx) {
tv.setBackgroundResource(R.drawable.tile_sended_xxx);
} else {
switch ((int) wt.getActivityId()) {
case Const.ACTIVITY_WALK:
tv.setBackgroundResource(R.drawable.tile_sended_walk);
break;
case Const.ACTIVITY_AUTO:
tv.setBackgroundResource(R.drawable.tile_sended_auto);
break;
default:
tv.setBackgroundResource(R.drawable.tile_sended_work);
break;
}
}还有我的一件抽屉(蓝色背景,咖啡图标):
<item>
<shape
android:padding="0dp"
android:shape="rectangle">
<solid android:color="@color/tile_sended_xxx"/>
<corners
android:bottomLeftRadius="4dp"
android:bottomRightRadius="4dp"
android:topLeftRadius="4dp"
android:topRightRadius="4dp"/>
</shape>
</item>
<item
android:drawable="@drawable/coffee"
android:gravity="center">
</item>问题是,有时只渲染背景(黄色/蓝色),但图标不可见。
它发生在不同的模拟器中,它发生在真实的设备上。
我不知道如何调试/解决这个问题。任何帮助都将被推荐。
我还添加了一些屏幕,以显示Android Studio显示它正常。


发布于 2021-05-25 00:10:52
解决后,它发生在其他地方,我正在设置可绘制的色调颜色,即黄色,并且该更改被保存到资源中以供以后使用。后来,当使用图层列表时,我可以在黄色背景上绘制黄色(而不是黑色)。
因此,不是更改“全局”资源:
Drawable d = ContextCompat.getDrawable(getActivity(), R.drawable.walk);
d.setTint(getActivity().getColor(R.color.tile_sended));要进行“本地”资源复制,应使用mutate():
Drawable d = ContextCompat.getDrawable(getActivity(), R.drawable.walk).mutate();
d.setTint(getActivity().getColor(R.color.tile_sended));https://stackoverflow.com/questions/67350989
复制相似问题