0

我正在尝试旋转 ImageView 及其原始位置(旋转图像和视图)。这样旋转后,当我在当前位置单击旋转图像时,它应该只能在旋转位置单击。

对于此解决方案,我正在尝试以下代码。但是它正在旋转一切正常。旋转结束后,我需要将 ImageView 和 Image 放在旋转的位置,使其只能点击那里。但它不会成功。我无法旋转图像位置轴点以正确放置。任何人都可以提出解决此问题的方法。

仅供参考-它应该适用于 Gingerbread 版本 android-9

 aniView1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e("", "Clicked on IMAGE VIEW - 1");
            }
        });

        RotateAnimation rotate5 = new RotateAnimation(0, 150,
                Animation.INFINITE, 100, Animation.INFINITE, 250);
        //rotate5.setFillAfter(true);
        rotate5.setDuration(2000);
        rotate5.setInterpolator(new LinearInterpolator());
        aniView1.setAnimation(rotate5);

        rotate5.setAnimationListener(new Animation.AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {

                int newTop = (int) (aniView1.getTop() + aniView1.getWidth());

                aniView1.layout(aniView1.getLeft()-200, newTop,
                        aniView1.getRight(),
                        aniView1.getBottom() + aniView1.getMeasuredWidth());

                // aniView1.setLayoutParams(new
                // RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT));

            }
        });
4

2 回答 2

1

尝试这个。它对我有用。动画状态将从那里持续存在

编辑:

好的,我可以在我的应用程序中使用以下代码来做到这一点:

Animation rotateAnim = new RotateAnimation(0, 360, Animation.ABSOLUTE, Animation.ABSOLUTE, Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF);
        rotateAnim.setDuration(5000);
        rotateAnim.setRepeatCount(1);
        rotateAnim.setInterpolator(new AccelerateInterpolator());
        rotateAnim.setRepeatMode(Animation.REVERSE);
        rotateAnim.setFillEnabled(true);
        rotateAnim.setFillAfter(true);
于 2012-11-07T10:58:12.060 回答
0

把这个文件放在android res --> anim --> loading_rotation.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"/>

在你的活动中

view.startAnimation(AnimationUtils.loadAnimation(context,
                R.anim.loading_rotation));

和你想停下来的地方只是打电话

view.clearAnimation();
于 2012-11-07T11:21:07.187 回答