Android的 - 翻转图像的XML [英] Android - flip image in xml

查看:185
本文介绍了Android的 - 翻转图像的XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要翻转图像按钮的背景XML。我见过的例子,如何做到这一点,但它是通过编程的方式:<一href="http://xjaphx.word$p$pss.com/2011/06/26/image-processing-image-flipping-mirroring">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>

  

这篇关于Android的 - 翻转图像的XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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