프레임 레이아웃에 textview 및 imageview가 있습니다. 이미지의 손가락과 함께 텍스트를 이동하고 싶습니다.텍스트보기를 이동하는 방법은 무엇입니까?
<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>
몇 가지 코드를 시도하지만 올바르게 작동하지 않습니다.
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;
}
왜 애니메이션을 사용하지 않는를 사용하여 대답을 얻었다 ??? – PedroAGSantos
위의 코드가 작동하지 않습니까? 와트 문제가 점점? 오류를 게시 할 경우? – Randroid
오류가 아니며, 로그에 아무것도 표시되지 –