public class Quiz extends Activity {
int windowwidth;
int windowheight;
ImageView ima ima2;
private View selected_item = null;
private int offset_x = 0;
private int offset_y = 0;
private android.widget.LinearLayout.LayoutParams layoutParams1,
layoutParams2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.quiz);
windowwidth = getWindowManager().getDefaultDisplay().getWidth();
windowheight = getWindowManager().getDefaultDisplay().getHeight();
System.out.println("width" + windowwidth);
System.out.println("height" + windowheight);
//on touch listener for image view
ima1 = (ImageView) findViewById(R.id.shuffledimage);
ima1.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
layoutParams1 = (LinearLayout.LayoutParams) ima1
.getLayoutParams();
try {//action performed in image view
switch (event.getActionMasked()) {
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;
}
layoutParams1.leftMargin = x_cord - 25;
layoutParams1.topMargin = y_cord - 75;
ima1.setLayoutParams(layoutParams1);
break;
default:
break;
}
} catch (Exception e) {
// TODO: handle exception
e.getMessage();
}
return true;
}
});
ima2 = (ImageView) findViewById(R.id.userimage);
ima2.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
layoutParams2 = (LinearLayout.LayoutParams) ima2
.getLayoutParams();
try {
switch (event.getActionMasked()) {
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;
}
layoutParams2.leftMargin = x_cord - 25;
layoutParams2.topMargin = y_cord - 75;
ima2.setLayoutParams(layoutParams2);
break;
default:
break;
}
} catch (Exception e) {
e.getMessage();
}
return true;
}
});
}
}
//xmlファイル
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ipodbackground"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="@drawable/headingmain1"
android:gravity="center_horizontal" >
<Button
android:id="@+id/button1"
android:layout_width="65dp"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:background="#00000000" />
<Button
android:id="@+id/button2"
android:layout_width="40dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#00000000" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="@drawable/quiztitle1" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="75dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp" >
<LinearLayout
android:id="@+id/l1"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginRight="25dp"
android:background="@drawable/box"
android:orientation="horizontal" >
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:text="TextView" />
<ImageView
android:id="@+id/userimage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="160dp"
android:layout_weight="1"
android:background="#FFFFFF"
android:src="@drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:layout_toRightOf="@+id/l1" >
<ImageView
android:id="@+id/shuffledimage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/iconsearch" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
//ある画像ビューから別の画像ビューに画像をドラッグアンドドロップしたいのですが、上記のコードセクションでは、ドラッグすると画像を正しくドラッグできますが、画像をソース画像ビューにドロップできません。誰でも解決策を教えてください