Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RotateDrawable Programmatically in android

How can i give fromFegrees , toDegrees and android:color="#000000" programmatically?

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item >


        <rotate 
            android:fromDegrees="45"
            android:toDegrees="45"
            android:pivotX="-40%"
            android:pivotY="87%" >

            <shape 
            android:shape="rectangle"  >
            <stroke android:color="@android:color/transparent" android:width="10dp"/>
            <solid  
                android:color="#000000"  />
        </shape>

        </rotate>
    </item>
</layer-list>

i am using this xml in background of view.

i have to create triangle programmatically. so need to create RotationDrawable programmatically.

like image 652
Sanket Kachhela Avatar asked Feb 27 '14 13:02

Sanket Kachhela


People also ask

How do I rotate a picture on android?

Drag the dots to the edges of your desired photo or tap Auto. To rotate a photo 90 degrees, tap Rotate . To make minor adjustments to straighten the photo, use the dial above Rotate . To automatically straighten the photo, tap Auto.

How do I reverse an image in Android Studio?

Launch the app and tap on the "+" icon present at the bottom-right corner of the app. Now, select the "Image Gallery" of your Android device. Select an image from the gallery that you want to reverse search.

What is rotate in android?

Auto rotate is a feature on smartphones and tablets that matches the screen's orientation with the device's actual orientation. It uses the gyroscope to detect if a device is used vertically or horizontally, and changes the display setting to either portrait or landscape mode accordingly.

What is rotate animation in android?

In android, Rotate animation is used to change the appearance and behavior of the objects over a particular interval of time. The Rotate animation will provide a better look and feel for our applications.


1 Answers

here's a nice solution for putting a rotated drawable for an imageView:

RotateAnimation anim = new RotateAnimation(0.0f, 360.0f , Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF, .5f);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(3000);
iv.setAnimation(anim);
iv.startAnimation(anim);
like image 87
Harshit Rathi Avatar answered Sep 19 '22 16:09

Harshit Rathi