내 문제는 ImageView의 onTouchEvent 이미지를 이동합니다. 하나의 화면에 두 개의 이미지가 있지만 이미지를 터치하면 문제가 발생합니다. & 완벽하게 작동하지만 이미지 1을 터치하면 문제가 발생합니다. 그 순간 image2가 원래 위치로 이동하기 때문에 문제가 무엇입니까? 나쁜 영어 의사 소통에 죄송합니다.터치 이벤트 문제 이미지보기
도와주세요. ,, u는 여기에 더 어 Repu을 가지고 있지만
main.xml에
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:layout_width="50sp" android:layout_height="50sp"
android:id="@+id/image" android:src="@drawable/image">
</ImageView>
<ImageView android:layout_y="30dip" android:layout_x="118dip"
android:layout_width="50sp" android:layout_height="50sp" android:id="@+id/image1"
android:src="@drawable/image1">
</ImageView>
</RelativeLayout>
MainActivity.java:-
public class MainActivity extends Activity implements OnTouchListener {
int windowwidth;
int windowheight;
private RelativeLayout.LayoutParams layoutParams;
private RelativeLayout.LayoutParams layoutParams1;
ImageView image, image1;
int x_cord, y_cord;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
windowwidth = getWindowManager().getDefaultDisplay().getWidth();
windowheight = getWindowManager().getDefaultDisplay().getHeight();
image = (ImageView) findViewById(R.id.image);
image.setOnTouchListener(this);
image1 = (ImageView) findViewById(R.id.image1);
image1.setOnTouchListener(this);
}
public boolean onTouch(View v, MotionEvent event) {
switch (v.getId()) {
case R.id.image:
System.out.println("Image is Touched");
image = (ImageView) findViewById(R.id.image);
layoutParams = (RelativeLayout.LayoutParams) image.getLayoutParams();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
int x_cord = (int) event.getRawX();
int y_cord = (int) event.getRawY();
if (x_cord > windowwidth) {
x_cord = windowwidth;
}
if (y_cord > windowheight) {
y_cord = windowheight;
}
layoutParams.leftMargin = x_cord - 25;
layoutParams.topMargin = y_cord - 75;
image.setLayoutParams(layoutParams);
break;
default:
break;
}
case R.id.image1:
System.out.println("Image 1 is Touched");
image1 = (ImageView) findViewById(R.id.image1);
layoutParams1 = (RelativeLayout.LayoutParams) image1
.getLayoutParams();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
x_cord = (int) event.getRawX();
y_cord = (int) event.getRawY();
if (x_cord > windowwidth) {
x_cord = windowwidth;
}
if (y_cord > windowheight) {
y_cord = windowheight;
}
layoutParams1.leftMargin = x_cord - 25;
layoutParams1.topMargin = y_cord - 75;
image1.setLayoutParams(layoutParams1);
break;
default:
break;
}
}
return true;
}
}
당신의 코드는 이미지보기로도 작업하고 있지만 문제는 큰 해상도 이미지 (예 : 320 * 480)를 사용하는 경우 이미지가 제대로 움직이지 않을 때입니다. –
Hello Raj 수행 방법이 코드를 확대, 축소 및 회전합니다. 도와주세요. –
이 작은 코드로는이 링크를 볼 수 없습니다 : http://dl.dropbox.com/u/38493970/Full.java 이것을 사용하면 패닝 (panning) 및 확대/축소가 가능한 코드를이 코드와 통합 할 수 있습니다 .. –