【问题标题】:Rotate icons/views along a circular path, on scroll - Android在滚动时沿圆形路径旋转图标/视图 - Android
【发布时间】:2012-05-16 19:44:15
【问题描述】:

我基本上是在尝试实现类似于this 的东西。遗憾的是,这是一个 iOS 教程。

我已经搜索了大多数可能的关键字以循环方式移动某些内容,但找不到任何开始。至少有人可以提供有关如何在 android 上被黑客入侵的任何提示吗?请。

谢谢。

【问题讨论】:

    标签: android android-layout android-animation android-view android-scrollview


    【解决方案1】:

    我使用旋转动画来围绕一个点旋转图像。

        double r = Math.atan2(evt.getX() - turntable.getWidth() / 2, turntable.getHeight() / 2 - evt.getY());
        rotation = (int) Math.toDegrees(r);
    
        if (evt.getAction() == MotionEvent.ACTION_MOVE)
            {
                    x= (int)evt.getX();
                    y = (int)evt.getY();
                        rotateAnim = new RotateAnimation(angle,rotation-50,200,100);
                        rotateAnim.setFillAfter(true);
                        ImageView.setanimation(rotateAnim );
                        ImageView.startAnimation(rotateAnim);
              }
    

    你也可以使用矩阵

        float newRot = new Float(rot);
    
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.disc);
    
        Matrix matrix = new Matrix();
        matrix.postRotate(newRot - 50);
    
        Bitmap redrawnBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
        turntable.setImageBitmap(redrawnBitmap);  
    

    【讨论】:

      【解决方案2】:

      这在自定义控件中很容易做到。只需创建一个扩展 View 的类并覆盖 draw() 方法。然后您可以监听触摸并计算用户旋转控件的距离。然后,您只需要使用该数据来旋转画布并在其上绘制数字。

      -= 更新 =- 当您覆盖 draw 方法时,您将获得一个 Canvas 对象。该对象可让您随心所欲地绘制它。它看起来像这样:

      @Override
      public void draw(Canvas c)
      {
          c.rotate(amount);
          c.drawBitmap(myImage);
      }
      

      这是完整的Canvas Documentation 的链接。

      【讨论】:

      • 感谢回复,问题是旋转部分。如何使图标/图像按钮(在我的情况下)以圆形路径旋转,类似于在滚动视图上上下滚动的效果。我现在正在学习android,请你给我更多的澄清。
      猜你喜欢
      • 1970-01-01
      • 2016-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-20
      • 1970-01-01
      • 1970-01-01
      • 2015-04-02
      相关资源
      最近更新 更多