我正在研究项目用户将图像移动到一个位置到屏幕上的另一个位置.我写了一个示例代码来移动图像,但问题是如果我移动一个图像,相邻的图像也开始移动..这是示例代码.任何一个想法.
Main.java
public class MainActivity extends Activity {
int windowwidth;
int windowheight;
ImageView ima1,ima2;
private android.widget.RelativeLayout.LayoutParams layoutParams ;
// private android.widget.RelativeLayout.LayoutParams layoutParams ;
//private android.widget.RelativeLayout.LayoutParams layoutParams ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
windowwidth = getWindowManager().getDefaultDisplay().getWidth();
windowheight = getWindowManager().getDefaultDisplay().getHeight();
System.out.println("width" +windowwidth);
System.out.println("height" +windowheight);
ima1 = (ImageView)findViewById(R.id.imageview1);
ima1.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
layoutParams = (RelativeLayout.LayoutParams) ima1.getLayoutParams();
switch(event.getAction())
{
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
int x_cord = (int) event.getRawX();
int y_cord = (int) event.getRawY();
System.out.println("value …Run Code Online (Sandbox Code Playgroud) 我正在尝试开发一个Android应用程序,用户应该能够将图像从网格的一个单元格拖动到另一个单元格.为了实现这一点,我需要在Android 3.0中引入的拖放API,但我的应用程序应该在Android 2.2中运行.那么,有没有办法使用Touch事件实现这一点?如果是,那么请提供一些代码片段或简要介绍它的任何链接.