I ran into the problem of dragging and dropping the layout on a Google Map. When I tried to drag this layout, it will disappear.
I am using this code: -
imggg.setOnTouchListener(new View.OnTouchListener() {
int prevX,prevY;
@Override
public boolean onTouch(View v, MotionEvent event) {
final RelativeLayout.LayoutParams par=(RelativeLayout.LayoutParams)v.getLayoutParams();
switch(event.getAction())
{
case MotionEvent.ACTION_MOVE:
{
par.topMargin+=(int)event.getRawY()-prevY;
prevY=(int)event.getRawY();
par.leftMargin+=(int)event.getRawX()-prevX;
prevX=(int)event.getRawX();
v.setLayoutParams(par);
return true;
}
case MotionEvent.ACTION_UP:
{
par.topMargin+=(int)event.getRawY()-prevY;
par.leftMargin+=(int)event.getRawX()-prevX;
v.setLayoutParams(par);
return true;
}
case MotionEvent.ACTION_DOWN:
{
prevX=(int)event.getRawX();
prevY=(int)event.getRawY();
par.bottomMargin=-2*v.getHeight();
par.rightMargin=-2*v.getWidth();
v.setLayoutParams(par);
return true;
}
}
return false;
}
});
here, imggg is the relative layout object and this is the overlay on the google map. Now I want to drag this layout to the touch, as we drag the marker from one position to another.
Please help me with this. Thanks in advance.
source
share