2015-12-30 36 views
0

我可以對指向屏幕中心的圖像進行評分。但它旋轉的半徑很大,部分擋住了屏幕。如何設置半徑像說100像素。如何設置旋轉動畫的半徑

DisplayMetrics displaymetrics = new DisplayMetrics(); 
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); 

    screenWidthPixel = displaymetrics.widthPixels; 
    screenHeightPixel = displaymetrics.heightPixels; 

    center_x = screenWidthPixel/2; 
    center_y = screenHeightPixel/2; 

    //RotateAnimation rotate = new RotateAnimation(0, 360, Animation.ABSOLUTE, center_x, Animation.ABSOLUTE, center_y); 
    RotateAnimation rotate = new RotateAnimation(0, 360, center_x, center_y); 
    rotate.setDuration(2000); 
    rotate.setRepeatCount(Animation.INFINITE); 
    rotate.setInterpolator(new LinearInterpolator()); 

    ImageView image= (ImageView) findViewById(R.id.test_img); 

    image.setAnimation(rotate); 

我看起來像rotate.setRadius(100)

回答

1

試試這個:

RotateAnimation()參數刪除center_x,center_y,而是在屏幕的中心layout.xml設置ImageView

Activity.java

RotateAnimation rotate = new RotateAnimation(0, 360); 
rotate.setDuration(2000); 
rotate.setRepeatCount(Animation.INFINITE); 
rotate.setInterpolator(new LinearInterpolator()); 
ImageView image= (ImageView) findViewById(R.id.test_img); 
image.setAnimation(rotate); 

layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/test_img" 
     android:src="@mipmap/ic_launcher" 
     android:layout_centerInParent="true" 
     /> 
</RelativeLayout> 
+0

在這裏,IMG將自身在旋轉的中心,如果我把機器人:layout_centerInParent = 「真」 我想在img以100px的半徑爲中心旋轉屏幕的中心點 – Abhijit