2012-11-07 60 views
0

我想旋转ImageView以及其原始位置(旋转图像以及视图)。所以,旋转后,当我点击旋转的图像在其当前位置,它应该只能在旋转的位置单击。旋转ImageVIew应该在Android下面的旋转位置点击HoneyComb版本

对于此解决方案,我尝试下面的代码。然而它正在旋转很好。旋转结束后,我需要将ImageView和Image放置在旋转的位置,使其只能在那里点击。但是它没有成功。我无法将图像位置轴点旋转到正确位置。任何人都可以请建议一种方法来解决这个问题。

仅供参考,它应该在姜饼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)); 

      } 
     }); 

回答

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); 
+0

没有老板,我旋转的图像也应该被点击,这意味着完整的图像以及视图应该完全从原始位置到旋转位置 – candy

+0

请检查编辑答案,我只能点击该位置的旋转图像。希望它适用于您的情况 –

+0

请更改360以外的旋转度并尝试?在你上面的代码中,你正在旋转到相同的位置。请尝试其他情况下30 60 90 120度360以下,并尝试让我知道 – candy

0

将在Android的资源文件 - >阿尼姆 - > 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(); 
+0

我已在第一个答案中评论,因为我的旋转图像应该能够点击,其旋转后请仔细阅读问题,我尝试了所有这些东西这些将只是旋转图像而不是从原始位置完整的视图。 – candy

+0

此代码仅用于旋转,旋转的图像无法在其旋转位置点击 – candy

+0

对于任何点击事件,您可以设置监听器,当然,您可以在旋转之前/之后或同时点击,并通过窗口小部件/视图调用监听器。 –