I have a relative layout in which i have a TextView having some text "Hi ! This is john". I want to move the text to any position i want on the screen, on touching the text.I am using onTouchListener() on the Text View.Can anybody please help me.
Asked
Active
Viewed 6,290 times
1
-
set animation on textView – Engr Waseem Arain Apr 01 '14 at 12:54
2 Answers
0
Follow that carefully, very how set animation? Android Working with XML Animations then visit that android: move a view on touch move (ACTION_MOVE)

Community
- 1
- 1

Engr Waseem Arain
- 1,163
- 1
- 17
- 36
-
Thanks.It Works fine.But text having more words is not displaying.how to display text having more number of words. – Lakshmipathi Apr 01 '14 at 13:19
-
0
Set onTouch
listner on your TextView
and according to the position of it Move it to another location you want on MotionEvent.ACTION_UP
event..
private final static int START_DRAGGING = 0;
private final static int STOP_DRAGGING = 1;
private int status;
int flag=0;
float xAxis = 0f;
float yAxis = 0f;
float lastXAxis = 0f;
float lastYAxis = 0f;
...
@Override
public boolean onTouch(View v, MotionEvent me){
if(me.getAction()==MotionEvent.ACTION_DOWN){
status = START_DRAGGING;
final float x = me.getX();
final float y = me.getY();
lastXAxis = x;
lastYAxis = y;
v.setVisibility(View.INVISIBLE);
}else if(me.getAction()==MotionEvent.ACTION_UP){
status = STOP_DRAGGING;
flag=0;
v.setVisibility(View.VISIBLE);
}else if(me.getAction()==MotionEvent.ACTION_MOVE){
if (status == START_DRAGGING){
flag=1;
v.setVisibility(View.VISIBLE);
final float x = me.getX();
final float y = me.getY();
final float dx = x - lastXAxis;
final float dy = y - lastYAxis;
xAxis += dx;
yAxis += dy;
v.setX((int)xAxis);
v.setY((int)yAxis);
v.invalidate();
}
}
return false;
}

Akshay
- 6,029
- 7
- 40
- 59
-
-
-
-
I am doing my app on API level 8 or above.But setX() in your code is of API level 11 or above.So I am unable to execute it. – Lakshmipathi Apr 02 '14 at 06:13
-
try getRawX() and getRawY() insted of setX() and setY() will help you for sure,,,and let me know does it work or not?? – Akshay Apr 02 '14 at 06:41
-
It is saying that we should not use getRawX() and getRawY() for the view v. – Lakshmipathi Apr 02 '14 at 12:35