7

どうすればfromFegreestoDegreesそしてandroid: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>

ビューのバックグラウンドでこのxmlを使用しています。

プログラムで三角形を作成する必要があります。プログラムで RotationDrawable を作成する必要があります。

4

3 に答える 3

6

これは、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);
于 2014-02-27T13:25:21.433 に答える
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);
于 2014-02-27T13:24:06.613 に答える