Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to rotate a drawable in the xml description?
    primarykey
    data
    text
    <p>I am creating an app, with resources that can be reused (because buttons are always the same, but mirrored or rotated). I do want to use the same resource so I don't have to add 3 more resources that are exactly like the original but rotated. But I also don't want to mix the code with things that can be declared in the XML or make transformations with a matrix that will cost processing time.</p> <p>I've got a two state button declared in an XML.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:state_pressed="true" android:drawable="@drawable/and_card_details_button_down_left_onclick" /&gt; &lt;!-- pressed --&gt; &lt;item android:drawable="@drawable/and_card_details_button_down_left" /&gt; &lt;!-- default --&gt; &lt;/selector&gt; </code></pre> <p>and I want to reuse the drawable because it will be the same but rotated 90º and 45º and I assign to the button as a drawable.</p> <pre><code>&lt;Button android:id="@+id/Details_Buttons_Top_Left_Button" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/details_menu_large_button" /&gt; </code></pre> <p>I know that I can rotate it with a <a href="http://developer.android.com/reference/android/graphics/drawable/RotateDrawable.html" rel="noreferrer"><code>RotateDrawable</code></a> or with a <a href="http://developer.android.com/reference/android/graphics/Matrix.html" rel="noreferrer"><code>Matrix</code></a> but as I already explained I don't like that approach.</p> <p>Is it possible to achieve that directly on the XML or what do you think that will be the best way to do it? Put all resources but rotated, rotate them in the code?</p> <p>--- EDIT --- The answer of @dmaxi works great, this is how to combine it with an item list :)</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:state_pressed="true"&gt; &lt;rotate android:fromDegrees="90" android:toDegrees="90" android:pivotX="50%" android:pivotY="50%" android:drawable="@drawable/and_card_details_button_up_onclick"/&gt; &lt;/item&gt; &lt;item&gt; &lt;rotate android:fromDegrees="90" android:toDegrees="90" android:pivotX="50%" android:pivotY="50%" android:drawable="@drawable/and_card_details_button_up_onclick"/&gt; &lt;/item&gt; &lt;/selector&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload