让用户删除图像视图

时间:2016-05-26 11:32:48

标签: android imageview

是否有办法允许用户删除图像视图,如果它已经有一个用于拖放的触摸侦听器?还有另一种方法可以在用户需要时删除一个吗? 这是我现在的聆听者。如何判断我是否要删除某个区域?

private final class myListener implements View.OnTouchListener {
    public boolean onTouch(View view, MotionEvent event) {
        final int x = (int) event.getRawX();
        final int y = (int) event.getRawY();

        switch (event.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN:
                RelativeLayout.LayoutParams layparms = (RelativeLayout.LayoutParams) view.getLayoutParams();
                xCoord = x - layparms.leftMargin;
                yCoord = y - layparms.topMargin;
                break;
            case MotionEvent.ACTION_UP:
                break;
            case MotionEvent.ACTION_POINTER_DOWN:
                break;
            case MotionEvent.ACTION_POINTER_UP:
                break;
            case MotionEvent.ACTION_MOVE:
                RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)view.getLayoutParams();
                layoutParams.leftMargin = x - xCoord;
                layoutParams.topMargin = y - yCoord;
                layoutParams.rightMargin = -250;
                layoutParams.bottomMargin = -250;
                view.setLayoutParams(layoutParams);
                break;
            default:
                break;
        }
        return true;
    }

0 个答案:

没有答案