使用可绘制资源 [英] Using drawable resources

查看:185
本文介绍了使用可绘制资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个问题,查看跟踪堆栈:

  E / AndroidRuntime(2410):org.xmlpull.v1.XmlPullParserException:二进制XML文件中的行#5:产生的原因<位图>需要一个有效的src属性
 

我的XML文件是这样的:

 <层列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <项目>
        <位图机器人:SRC =@可绘制/ btn_1/>
    < /项目>
< /层列表>
 

btn_1是绘制资源另一个XML文件 当我用图片代替XML(*。PNG)绘制的它的确定。

我可以用一个可绘制资源作为SRC为位图? 以防万一这是我的btn_1.xml文件。它不工作,即使btn_1文件中没有商品。

 <层列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
<项目机器人:可绘制=@可绘制/ btn_arrow_bg_red/>
<项目>
    <位图
        机器人:重力=中心
        机器人:SRC =@可绘制/ btn_arrow_white/>
< /项目>
< /层列表>
 

解决方案

您不能拥有的 XML绘制的源位图。因为例如,如果有可能的话,就可能错误地通过调用XML来自己创造一个黑洞。

让假设,您有一个XML绘制的 A 里面有一个位图卫生组织源绘制的 B 。但在绘制的 B ,它有一个位图卫生组织源绘制的 A 。这将创建一个循环回路,不能得到解决。这就是为什么你需要提供一个图像作为源位图,以避免任何混淆

I have this problem, see the trace stack:

E/AndroidRuntime(2410): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #5: <bitmap> requires a valid src attribute

My xml file looks like:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <bitmap android:src="@drawable/btn_1"/>
    </item>
</layer-list>

btn_1 is another xml file in drawable resources When i'm using an image(*.png) instead of xml drawable it's ok.

Can I use a drawable resource as src to bitmap? Just in case here is my btn_1.xml file. It doesn't work even if btn_1 file have no items.

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/btn_arrow_bg_red"/>
<item>
    <bitmap
        android:gravity="center"
        android:src="@drawable/btn_arrow_white" />
</item>
</layer-list>

解决方案

You cant have an xml drawable as source for bitmap. Because for example if it was possible, then it could mistakenly create a black-hole by calling xml to itself.

Lets suppose, you have an xml drawable A which has a bitmap whos source is drawable B. But in drawable B, it has a bitmap whos source is drawable A. This will create a circular loop which cant be resolved. That is why you need to provide an image as a source for bitmap to avoid any confusion

这篇关于使用可绘制资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆