How to move textview in vertical direction when I tap on button?
msgtxt.setOnTouchListener(new OnTouchListener() {
@SuppressLint("ClickableViewAccessibility") public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
drag(event, v);
return false;
}
});
public void drag(MotionEvent event, View v)
{
RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams) v.getLayoutParams();
switch(event.getAction())
{
case MotionEvent.ACTION_MOVE:
{
params.topMargin = (int)event.getRawY() - (v.getHeight());
params.leftMargin = (int)event.getRawX() - (v.getWidth()/2);
v.setLayoutParams(params);
break;
}
}
}
As you can see above code, I can move the textview using onTouchListener but here the text in the textview is also moving that I don't want. I am sharing an image where I have mentioned my requirement.