画像を任意の方向に動かしたい場合は、次のステップに従う必要がある方向をピントアウトする必要があります step -1 float dx = 0, dy = 0, x = 0, y = 0, z = 0, w = 0 、dz = 0、dw = 0; 《このユーフォーコーディネート》
public void StickerPopulate(){
LinerLayoutInfate.removeAllViews();
shstickerBaseAdaptor = new ShstickerBaseAdaptor(getApplicationContext());
View shstickerView = getLayoutInflater().inflate(R.layout.shareimage,
null);
Gallery shsticker_gallery = (Gallery) shstickerView
.findViewById(R.id.shsticker_gallery);
shsticker_gallery.setAdapter(new ShstickerBaseAdaptor(
ImageEditingClass.this));
shsticker_gallery.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
StickerRelativeLayout = (RelativeLayout) findViewById(R.id.shsticker_relativeLayout1);
RelativeLayout.LayoutParams layoutParams;
layoutParams = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
final ImageView crossBtn = new ImageView(
getApplicationContext());
crossBtn.setBackgroundResource(R.drawable.cross);
crossBtn.setMaxWidth(300);
crossBtn.setMaxHeight(200);
crossBtn.setPadding(10, 10, 10, 10);
final ImageView view = new ImageView(getApplicationContext());
view.setImageResource(shstickerBaseAdaptor.shstickerImage[arg2]);
view.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
windowwidth = getWindowManager().getDefaultDisplay()
.getWidth();
windowheight = getWindowManager().getDefaultDisplay()
.getHeight();
android.widget.RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view
.getLayoutParams();
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
dx = event.getRawX() - layoutParams.leftMargin;
dy = event.getRawY() - layoutParams.topMargin;
dz = event.getRawX() - layoutParams.bottomMargin;
dw = event.getRawX() - layoutParams.rightMargin;
break;
case MotionEvent.ACTION_MOVE:
RelativeLayout.LayoutParams mParams = (RelativeLayout.LayoutParams) view
.getLayoutParams();
x = event.getRawX();
y = event.getRawY();
layoutParams.leftMargin = (int) (x - dx);
layoutParams.topMargin = (int) (y - dy);
layoutParams.bottomMargin = (int) (z - dz);
layoutParams.rightMargin = (int) (w - dw);
view.setLayoutParams(layoutParams);
break;
default:
break;
}
return true;
}
});
StickerRelativeLayout.addView(crossBtn, layoutParams);
StickerRelativeLayout.addView(view, layoutParams);
// }
Toast.makeText(ImageEditingClass.this, "you click" + arg2,
Toast.LENGTH_SHORT).show();
}
});
LinerLayoutInfate.addView(shstickerView);
}