2012-03-02 18 views
0

私は車輪を持っている、私はその位置に回転させたい。私のコードはこのイメージを回転させていますが、その位置を変えることになります。私はこの場所を固定したいと思っています。ダイヤル画像をその姿勢で回転させる方法。

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    dialImage = (ImageView) findViewById(R.id.inner_dial); 

    float rotation = (float) Math.toDegrees(90); 
    Matrix matrix = new Matrix(); 
    matrix.postRotate(rotation); 

    bMap = BitmapFactory.decodeResource(getResources(), 
      R.drawable.inner_temp); 

    dialImage.setBackgroundResource(0); 

    Bitmap bMapRotate = Bitmap.createBitmap(bMap, 0, 0, bMap.getWidth(), 
      bMap.getHeight(), matrix, true); 
    dialImage.setImageBitmap(bMapRotate); 

} 

私のXMLファイル:

<?xml version="1.0" encoding="utf-8"?> 

<ImageView android:background="@drawable/inner_temp" 
    android:layout_height="wrap_content" android:id="@+id/inner_dial" 
    android:layout_width="wrap_content" android:layout_alignParentLeft="true" /> 

答えて

0

resanimフォルダのrotate.xmlを保存します。

<?xml version="1.0" encoding="UTF-8"?> 
<rotate 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:fromDegrees="0" 
    android:toDegrees="360" 
    android:pivotX="50%" 
    android:pivotY="50%" 
    android:repeatCount="infinite" 
    android:duration="1200" 
    android:interpolator="@android:anim/linear_interpolator" /> 
はあなたのアニメーションを開始

dialImage.startAnimation(AnimationUtils.loadAnimation(this, R.anim.rotate)); 

EDIT:

prgrammatically回転アニメーションを使用するには:

RotateAnimation anim = new RotateAnimation(fromDegrees, toDegrees, pivotXType, pivotXValue, pivotYType, pivotYValue); 
dialImage.startAnimation(anim); 

は、詳細な説明のために、このlinkに従ってください。

+0

thanks @ Vineet ,,,私のdegreeの値は変更されるので、rotate.xmlを使用することはできません – Andy

+0

私の学位の値が何を意味するのかは分かりませんでした。回転角度を360度にしてから変更したい場合や、将来角度が変わる場合はプログラムで使用できます。 –

+0

Yaa @Vineet私のアングルは変わるだろう。私はイメージを実際に回転させている。しかし、異なった2アングルのイメージは元の場所を動いている。 – Andy

1

問題は、座標系の基準点です。何が起こるかは、画像がこの基準点を中心に90度回転したことです。画像を回転させるには、画像の中心と座標系の基準点が同じであるように、画像の位置を変換する必要があります。

関連する問題