选择,图层列表和形状/位图相同的XML [英] Selector, Layer-list and shape/bitmap in the same xml
问题描述
我有一个xml这个code中的内绘制
文件夹:
I have this code in an xml inside the drawable
folder:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<layer-list>
<item>
<shape android:shape="rectangle">
<size android:width="90dp" android:height="90dp" />
<solid android:color="#9933CC" />
</shape>
</item>
<item>
<bitmap android:gravity="center" android:src="@drawable/main_achievements_synthesis" />
</item>
</layer-list>
</item>
<item>
<layer-list>
<item>
<shape android:shape="rectangle">
<size android:width="90dp" android:height="90dp" />
<solid android:color="#AA66CC" />
</shape>
</item>
<item>
<bitmap android:gravity="center" android:src="@drawable/main_achievements_synthesis" />
</item>
</layer-list>
</item>
</selector>
我用它来有2个状态(如一个按钮来使用)的图像。一切正常的模拟器和设备。
I use it to have an image with 2 states (to use as a button). Everything works as expected on emulator and devices.
我知道我可以创建不同的绘制XML和作个参考,以达到相同的结果。
I know that I can create different drawable xml and make a reference to achieve the same result.
我刚换到Android Studio和它表明我这个mesage:元素XXX在这里不允许
。它警告我一下图层列表和所有里面的标签。不过,正如我所说,这code的作品就好。
I just switched to Android Studio and it shows me this mesage: Element XXX is not allowed here
. It warns me about Layer-list and all the tags inside it. However, as I said, this code works just fine.
我应该切换我的code到分离XML的(知道我只会用一次),或在Android Studio的督察code错误?
Should I switch my code into separated XMLs (knowing that I will only use them once) or is an "error" in the Android Studio's Inspector Code?
请注意:我觉得我的code,可以优化,但我还没有想出如何尚未
NOTE: I think my code can be optimized, but I haven't figured out how yet.
推荐答案
这是Android Studio中的掉毛工具错误。请<文件中的错误href=\"https://$c$c.google.com/p/android/issues/list\">https://$c$c.google.com/p/android/issues/list.
This is an error in Android Studio's linting tool. Please file a bug at https://code.google.com/p/android/issues/list.
此外,您还可以通过优化一点点:
Also, you can optimize a little by using:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<selector>
<item android:state_pressed="true">
<shape android:shape="rectangle">
<size android:width="90dp" android:height="90dp" />
<solid android:color="#9933CC" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<size android:width="90dp" android:height="90dp" />
<solid android:color="#AA66CC" />
</shape>
</item>
</selector>
</item>
<item>
<bitmap
android:gravity="center"
android:src="@drawable/main_achievements_synthesis" />
</item>
</layer-list>
这篇关于选择,图层列表和形状/位图相同的XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!