我要翻转图像按钮的背景XML。我见过的例子,如何做到这一点,但它是通过编程的方式:http://xjaphx.word$p$pss.com/2011/06/26/image-processing-image-flipping-mirroring. 无论如何,我有一个XML文件(button_left_state.xml)如下图所示:
I want to flip image for button's background in xml. I've seen example how to do it, but it was programmatically way: http://xjaphx.wordpress.com/2011/06/26/image-processing-image-flipping-mirroring. Anyway, I have a xml file (button_left_state.xml) like below :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<rotate android:fromDegrees="180.0" android:toDegrees="180.0"
android:pivotX="50%" android:pivotY="50%" android:drawable="@drawable/buttonrightpressed" />
</item>
<item>
<rotate android:fromDegrees="180.0" android:toDegrees="0.0"
android:pivotX="50%" android:pivotY="50%" android:drawable="@drawable/buttonright"/>
</item>
</selector>
但是,这code只需旋转图像180度。 是否可以翻转图像在XML?
But this code just rotate image to 180 degrees. Is it possible to flip image in xml?
我解决我的问题,通过使用图层列表
:
I resolve my problem by using layer-list
:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient android:startColor="#9f9" android:centerColor="#000"
android:endColor="#0f0" android:angle="-90" />
<stroke android:width="1.0px" android:color="#444" />
<corners android:bottomRightRadius="7dip"
android:bottomLeftRadius="0.1dp"
android:topLeftRadius="0.1dp"
android:topRightRadius="7dip"/>
</shape>
</item>
<item>
<rotate android:fromDegrees="180.0" android:toDegrees="180.0"
android:pivotX="50%" android:pivotY="50%" android:drawable="@drawable/arrow_right" />
</item>