首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何设置RotateAnimation的半径

如何设置RotateAnimation的半径
EN

Stack Overflow用户
提问于 2015-12-31 06:56:59
回答 1查看 319关注 0票数 0

我可以对指向屏幕中心的图像进行评分。但它的旋转半径很大,部分遮挡了屏幕。如何设置半径,比如100像素。

代码语言:javascript
复制
    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)

EN

回答 1

Stack Overflow用户

发布于 2015-12-31 16:29:13

试试这个:

RotateAnimation()中删除center_x和center_y参数,在layout.xml中将ImageView设置在屏幕中央。

Activity.java

代码语言:javascript
复制
 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

代码语言:javascript
复制
<?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>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34538534

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档