我可以对指向屏幕中心的图像进行评级。但它在大半径内旋转,部分挡住了屏幕。如何设置半径,比如100 px。
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)
答案 0 :(得分:1)
试试这个:
从RotateAnimation()
移除 center_x,center_y 参数,并将ImageView
设置在layout.xml
的屏幕中央。
<强> 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>