RotateDrawable以编程方式在android中

San*_*ela 7 android shapedrawable animationdrawable

我怎么能放弃fromFegrees,toDegreesandroid:color="#000000"编程?

<?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>
Run Code Online (Sandbox Code Playgroud)

我在视图的背景中使用此xml.

我必须以编程方式创建三角形.所以需要以编程方式创建RotationDrawable.

Har*_*thi 5

这是一个很好的解决方案,用于为 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);
Run Code Online (Sandbox Code Playgroud)


Fli*_*xer 0

您可以使用矩阵以编程方式旋转图像:

rotationMatrix = new Matrix();
// Set the scale type of your ImageView to "Matrix"
yourImageView.setScaleType(ScaleType.MATRIX);

// to set the rotation to a specific degree:
rotationMatrix.setRotate(degrees);
// or add some degrees to the current rotation
rotationMatrix.postRotate(degrees);

// apply matrix to your ImageView
yourImageView.setImageMatrix(rotationMatrix);
Run Code Online (Sandbox Code Playgroud)