小编Vee*_*ena的帖子

在android中拖放图像

我米工作就一个字争夺游戏允许用户移动图像image..if图像不匹配,那么它应该回到它是从它那里原来的位置dragged.I写了一个示例代码移动图像,但这里的问题是,如果我移动一个图像,相邻的图像也开始移动..这是示例代码.

 /** Touchmoveimage.java*/
     package com.examples.Touchmoveimage;
     import android.app.Activity;
     import android.content.Intent;
     import android.os.Bundle;
     import android.view.MotionEvent;
     import android.view.View;
     import android.view.View.OnTouchListener;
     import android.widget.ImageView;
     import android.widget.LinearLayout.LayoutParams;
     public class Touchmoveimage extends Activity implements OnTouchListener{

int windowwidth;
int windowheight;

   private LayoutParams layoutParams ;
   private LayoutParams layoutParams1 ;
   @Override
   public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.main);

  windowwidth = getWindowManager().getDefaultDisplay().getWidth();
  windowheight = getWindowManager().getDefaultDisplay().getHeight();

  ImageView ball= (ImageView)findViewById(R.id.ball);
  ball.setOnTouchListener(this);

  ImageView ball1 = (ImageView)findViewById(R.id.ball1);
  ball1.setOnTouchListener(this); 

 }   
 public boolean onTouch(View v,MotionEvent event) {
 switch(v.getId())
 {
 case R.id.ball:
   ImageView ball= (ImageView)findViewById(R.id.ball);
   layoutParams = (LayoutParams) …
Run Code Online (Sandbox Code Playgroud)

android drag-and-drop image ontouchlistener

8
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×1

drag-and-drop ×1

image ×1

ontouchlistener ×1