I have textview and imageview in the frame layout, i want move the text along with finger on the image.
<FrameLayout
android:id="@+id/framelayout"
android:layout_marginTop="30dip"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<ImageView
android:id="@+id/ImageView01"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<TextView android:id="@+id/text_view"
android:layout_marginTop="30dip"
android:layout_width="wrap_content"
android:maxLines="20"
android:scrollbars="vertical"
android:layout_height="wrap_content"/>
</FrameLayout>
i try some code but it's not working properly tell me the correct way.
public boolean onTouch(View v, MotionEvent event) {
float x1 = 0, x2, y1 = 0, y2;
String direction;
switch(event.getAction()) {
case(MotionEvent.ACTION_DOWN):
x1 = event.getX();
y1 = event.getY();
break;
case(MotionEvent.ACTION_UP): {
x2 = event.getX();
y2 = event.getY();
float dx = x2-x1;
float dy = y2-y1;
// Use dx and dy to determine the direction
if(Math.abs(dx) > Math.abs(dy)) {
if(dx>0) direction = "right";
else direction = "left";
} else {
if(dy>0) direction = "down";
else direction = "up";
}
}
}
return false;
}
Check this code snippet,
i got answer by using this code