在Android中使用ImageView移动时,如何使ImageView跟随我的手指并旋转?

时间:2012-09-11 22:23:47

标签: android rotation imageview move

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

1 个答案:

答案 0 :(得分: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/