EditTextビューでonTouchのサイズ変更を正常に実装しましたが、同じコードがImageViewで機能していないようです。私のコードは基本的に、ビューの右下隅で onTouch を取得し、それに応じてビューのレイアウト パラメータを変更しています。同じ実装が ImageView で機能しない理由がわかりません。助けてください!!ありがとう!!:)
protected View.OnTouchListener viewTouchListener=new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
int x = (int) event.getX();
int y = (int) event.getY();
int width = view.getLayoutParams().width;
int height = view.getLayoutParams().height;
if (((x - width <= 20 && x - width > 0) || (width - x <= 20 && width - x > 0))&&(((y - height <= 20 && y - height > 0) || (height - y <= 20 && height - y > 0))) ){
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
Log.e(">>", "width:" + width + " height:" + height + " x:" + x + " y:" + y);
view.getLayoutParams().width = x;
view.getLayoutParams().height = y;
view.requestLayout();
break;
case MotionEvent.ACTION_UP:
break;
}
}
onTouchListener を ImageView に設定します。
mImageView.setOnTouchListener(viewTouchListener);