Guest User

Untitled

a guest
Sep 2nd, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. //On touch listener
  2.  
  3. image1.setOnTouchListener(new View.OnTouchListener() {
  4. @Override
  5. public boolean onTouch(View v, MotionEvent event) {
  6. layoutParams = (LayoutParams) image1.getLayoutParams();
  7. switch (event.getAction()) {
  8. case MotionEvent.ACTION_DOWN:
  9. break;
  10. case MotionEvent.ACTION_MOVE:
  11. int x_cord = (int) event.getRawX();
  12. int y_cord = (int) event.getRawY();
  13.  
  14. if (x_cord > windowwidth) {
  15. x_cord = windowwidth;
  16. }
  17. if (y_cord > windowheight) {
  18. y_cord = windowheight;
  19. }
  20.  
  21. layoutParams.leftMargin = x_cord - 25;
  22. layoutParams.topMargin = y_cord - 75;
  23.  
  24. image1.setLayoutParams(layoutParams);
  25. break;
  26. default:
  27. break;
  28. }
  29. return true;
  30. }
  31. });
  32.  
  33.  
  34. .Xml
  35.  
  36. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  37. android:layout_width="match_parent"
  38. android:layout_height="300dp"
  39. android:background="#888"
  40. android:orientation="vertical"
  41. >
  42.  
  43. <ImageView
  44. android:id="@+id/imageView2"
  45. android:layout_width="wrap_content"
  46. android:layout_height="wrap_content"
  47. android:src="@drawable/ic_launcher" />
  48.  
  49. <ImageView
  50. android:id="@+id/imageView1"
  51. android:layout_width="wrap_content"
  52. android:layout_height="wrap_content"
  53. android:layout_marginTop="10dp"
  54. android:layout_gravity="center"
  55. android:src="@drawable/image" />
  56. </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment