【问题标题】:How to make ImageView following my finger and rotate when moving with ImageView in Android?在Android中使用ImageView移动时如何使ImageView跟随我的手指并旋转?
【发布时间】:2012-09-11 22:23:47
【问题描述】:

亲爱的android专家我想问你如何让ImageView在移动时旋转。我有飞机的照片。当我 touch_down 并随之移动时,ImageView 会跟随我的手指并动态旋转。当我手指向上触摸时,ImageView 平面向上旋转,当我向左触摸时,ImageView 动态向左旋转。请你给我指路好吗?我正在寻找一些示例,并且只能使用屏幕上的固定点,而不是移动物体。我正在处理示例,例如示例 Calculate angle of touched point and rotate it in Android 。但是我有移动的物体,你能帮忙吗?![画出我需要的东西 - 动态跟随手指并旋转它][1]

【问题讨论】:

    标签: android rotation imageview move


    【解决方案1】:

    试试这个,

     public class abc extends Activity implements OnTouchListener 
        {
     ImageView img;
     protected void onCreate(Bundle savedInstanceState) 
     {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.one);
    
                img = (ImageView) findViewById(R.id.imageView1);
                img.setOnTouchListener(this);
     }
    
        public boolean onTouch(View v, MotionEvent event) 
    {
        switch (event.getAction())
        {
            case MotionEvent.ACTION_DOWN:
            {       
                  // Here u can write code which is executed after the user touch on the screen 
                     break; 
            }
            case MotionEvent.ACTION_UP:
            {             
                   // Here u can write code which is executed after the user release the touch on the screen    
                 break;
            }
            case MotionEvent.ACTION_MOVE:
            {  
               // Here u can write code which is executed when user move the finger on the screen   
                break;
            }
        }
        return true;
    }
    

    还要检查这个链接, http://obviam.net/index.php/moving-images-on-the-screen-with-androi/

    【讨论】:

    • 感谢您的回答,但问题是如何围绕移动路径旋转 ImageView。我不是在问如何制作 ontouch 事件。我有移动 ImageView,我需要围绕曲线路径旋转它。动态地,如果我向左、向右、向上、向下移动,天使取决于具体情况。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多