我可以对指向屏幕中心的图像进行评分。但它的旋转半径很大,部分遮挡了屏幕。如何设置半径,比如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)
发布于 2015-12-31 16:29:13
试试这个:
从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>https://stackoverflow.com/questions/34538534
复制相似问题