首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Layer-list drawable有时不能完全渲染

Layer-list drawable有时不能完全渲染
EN

Stack Overflow用户
提问于 2021-05-02 05:26:30
回答 1查看 17关注 0票数 0

我遇到了一个问题,我的图层列表绘制有时不能完全渲染。

在我的活动的onCreate中,我已经程序化地创建了一些TextViews,在onResume中,我正在调用web服务,在获得响应后,我会相应地更新这个TextViews。

代码语言:javascript
复制
   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;
        }
    }

还有我的一件抽屉(蓝色背景,咖啡图标):

代码语言:javascript
复制
<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显示它正常。

EN

回答 1

Stack Overflow用户

发布于 2021-05-25 00:10:52

解决后,它发生在其他地方,我正在设置可绘制的色调颜色,即黄色,并且该更改被保存到资源中以供以后使用。后来,当使用图层列表时,我可以在黄色背景上绘制黄色(而不是黑色)。

因此,不是更改“全局”资源:

代码语言:javascript
复制
Drawable d = ContextCompat.getDrawable(getActivity(), R.drawable.walk);
d.setTint(getActivity().getColor(R.color.tile_sended));

要进行“本地”资源复制,应使用mutate():

代码语言:javascript
复制
Drawable d = ContextCompat.getDrawable(getActivity(), R.drawable.walk).mutate();
d.setTint(getActivity().getColor(R.color.tile_sended));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67350989

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档