0

please give me sample moving image to my margin destination

ilustration

image        x (margin move image)

if image moving with drag image stoped moving to my margin

imageView.setOnTouchListener(new OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                int eid = event.getAction();
                switch (eid) {
                case MotionEvent.ACTION_MOVE:
                    RelativeLayout.LayoutParams mParams = (RelativeLayout.LayoutParams) imageView.getLayoutParams();
                    int x = (int) event.getRawX();
                    //int y = (int) event.getRawY();
                    TextView text = (TextView) findViewById(R.id.editText1);
                    text.setText("1");
                   mParams.setMargins(0, 0, 70, 0);
                    mParams.leftMargin = x+0;
                    //mParams.

                    imageView.setLayoutParams(mParams);

                    break;
                default:
                    break;
                }
                return true;
            }
        }
kembang
  • 9
  • 2

1 Answers1

1
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
        Gravity.NO_GRAVITY);

the 3rd param(Gravity.NO_GRAVITY) that I missed. use it you can position views at anywhere with setting width/height.

Refered from Android. How to move the imageview(set position/margin) when it is created

Community
  • 1
  • 1
Okky
  • 10,338
  • 15
  • 75
  • 122