Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. btn.setOnTouchListener(new OnTouchListener() {
  2. @Override
  3. public boolean onTouch(View view, MotionEvent me) {
  4. if (me.getAction() == MotionEvent.ACTION_DOWN) {
  5. status = START_DRAGGING;
  6. }
  7. if (me.getAction() == MotionEvent.ACTION_UP) {
  8. status = STOP_DRAGGING;
  9. Log.i("Drag", "Stopped Dragging");
  10. } else if (me.getAction() == MotionEvent.ACTION_MOVE) {
  11. if (status == START_DRAGGING) {
  12. System.out.println("Dragging");
  13.  
  14. GestureImageView image1 = (GestureImageView) findViewById(R.id.image1);
  15. GestureImageView image2 = (GestureImageView) findViewById(R.id.image2);
  16.  
  17. ImageView header = (ImageView) findViewById(R.id.imageHeader);
  18.  
  19. RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
  20. RelativeLayout.LayoutParams.WRAP_CONTENT,
  21. RelativeLayout.LayoutParams.WRAP_CONTENT);
  22.  
  23. lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
  24. margin1 = (int) me.getRawY() - 100;
  25. if (margin1 < header.getHeight() - btn.getHeight() / 3)
  26. margin1 = header.getHeight() - btn.getHeight() / 3;
  27. else if (margin1 > layout.getHeight() - 1.5
  28. * btn.getHeight() - btn3.getHeight())
  29. margin1 = (int) (layout.getHeight() - 1.5
  30. * btn.getHeight() - btn3.getHeight());
  31. lp.topMargin = margin1;
  32. btn.setLayoutParams(lp);
  33.  
  34. if (margin1 >= margin2 - 35) {
  35. RelativeLayout.LayoutParams newlp = new RelativeLayout.LayoutParams(
  36. RelativeLayout.LayoutParams.WRAP_CONTENT,
  37. RelativeLayout.LayoutParams.WRAP_CONTENT);
  38.  
  39. newlp.addRule(RelativeLayout.CENTER_HORIZONTAL);
  40. margin2 = margin1 + 35;
  41. newlp.topMargin = margin2;
  42. btn2.setLayoutParams(newlp);
  43.  
  44. RelativeLayout.LayoutParams newlp2 = new RelativeLayout.LayoutParams(
  45. RelativeLayout.LayoutParams.WRAP_CONTENT,
  46. RelativeLayout.LayoutParams.FILL_PARENT);
  47. newlp2.addRule(RelativeLayout.ABOVE, btn2.getId());
  48. newlp2.addRule(RelativeLayout.BELOW, header.getId());
  49. newlp2.bottomMargin = -(15 + margin2);
  50. image2.setLayoutParams(newlp2);
  51. image2.setAdditionalY(image2.getHeight(),
  52. margin2 - 85, image2.getScaledHeight()
  53. - margin2 - 85);
  54. }
  55.  
  56. RelativeLayout.LayoutParams lp3 = new RelativeLayout.LayoutParams(
  57. RelativeLayout.LayoutParams.WRAP_CONTENT,
  58. RelativeLayout.LayoutParams.FILL_PARENT);
  59. lp3.addRule(RelativeLayout.ABOVE, btn.getId());
  60. lp3.addRule(RelativeLayout.BELOW, header.getId());
  61. lp3.bottomMargin = -(15 + margin1);
  62. image1.setLayoutParams(lp3);
  63. image1.setAdditionalY(image1.getHeight(), margin1 - 50,
  64. image1.getScaledHeight() - margin1 - 50);
  65. }
  66. }
  67. return false;
  68. }
  69. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement