Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 拖放浮动操作菜单不显示';行不通_Java_Android - Fatal编程技术网

Java 拖放浮动操作菜单不显示';行不通

Java 拖放浮动操作菜单不显示';行不通,java,android,Java,Android,我刚刚创建了一个浮动动作菜单所有我需要的我想要这个浮动动作菜单可拖动我已经创建了一个拖放视图类并创建了一个浮动动作菜单对象,但它仍然不起作用这里是拖放类 package niko.dragdrop.view; import android.content.Context; import android.util.AttributeSet; import android.view.Gravity; import android.view.MotionEvent; import android.v

我刚刚创建了一个浮动动作菜单所有我需要的我想要这个浮动动作菜单可拖动我已经创建了一个拖放视图类并创建了一个浮动动作菜单对象,但它仍然不起作用这里是拖放类

package niko.dragdrop.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

/**
 * @author Niko
 * View Container to place the view wanted to be dragged
 */
public class DragDropView extends FrameLayout {

    /**
     * Default Constructor
     * @param context
     */
    public DragDropView(Context context) {
        super(context);
    }

    /**
     * Default Constructor
     * @param context
     * @param attrs
     */
    public DragDropView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    /**
     * Default Constructor
     * @param context
     * @param attrs
     * @param defStyle
     */
    public DragDropView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    /** Adding draggable object to the dragView
     * @param draggableView - object to be dragged
     * @param - x horizontal position of the view
     * @param - y vertical position of the view
     * @param - width width of the view
     * @param - height height of the view
     */
    public void AddDraggableView(View draggableObject, int x, int y, int width, int height) {
        LayoutParams lpDraggableView = new LayoutParams(width, height);
        lpDraggableView.gravity = Gravity.TOP;
        lpDraggableView.leftMargin = x;
        lpDraggableView.topMargin = y;
        if(draggableObject instanceof ImageView) {
            ImageView ivDrag = (ImageView) draggableObject;
            ivDrag.setLayoutParams(lpDraggableView);
            ivDrag.setOnTouchListener(OnTouchToDrag);
            this.addView(ivDrag);
        } 
        //TODO implement to do other type of view
//      else if(draggableObject instanceof TextView) {
//          TextView tvDrag = (TextView) draggableObject;
//          tvDrag.setLayoutParams(lpDraggableView);
//          tvDrag.setOnTouchListener(OnTouchToDrag);
//          this.addView(tvDrag);
//      } 
//      else if(draggableObject instanceof Button) {
//          Button btnDrag = (Button) draggableObject;
//          btnDrag.setLayoutParams(lpDraggableView);
//          btnDrag.setOnTouchListener(OnTouchToDrag);
//          this.addView(btnDrag);
//      }

    }

    /**
     * Draggable object ontouch listener
     * Handle the movement of the object when dragged and dropped
     */
    private View.OnTouchListener OnTouchToDrag = new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            FrameLayout.LayoutParams dragParam = (LayoutParams) v.getLayoutParams();
            switch(event.getAction())
            {
                case MotionEvent.ACTION_MOVE:
                {
                    dragParam.topMargin = (int)event.getRawY() - (v.getHeight());
                    dragParam.leftMargin = (int)event.getRawX() - (v.getWidth()/2);
                    v.setLayoutParams(dragParam);
                    break;
                }
                case MotionEvent.ACTION_UP:
                {
                //  dragParam.height = 150;
                //  dragParam.width = 150;
                    dragParam.height = v.getHeight();
                                dragParam.width = v.getWidth();
                    dragParam.topMargin = (int)event.getRawY() - (v.getHeight());
                    dragParam.leftMargin = (int)event.getRawX() - (v.getWidth()/2);
                    v.setLayoutParams(dragParam);
                    break;
                }
                case MotionEvent.ACTION_DOWN:
                {
                //  dragParam.height = 100;
                //  dragParam.width = 100;
                        dragParam.height = v.getHeight();
                                dragParam.width = v.getWidth();
                    v.setLayoutParams(dragParam);
                    break;
                }
            }
            return true;
        }

    };

}
这是浮动动作菜单属性

FloatingActionMenu mainFM;

private Context context;
    mainFM = (FloatingActionMenu) findViewById(R.id.mainFAB);
    context = this;
    FrameLayout llContainerMain = (FrameLayout) findViewById(R.id.content_frame);
    DragDropView dragDropView = new DragDropView(context);
    dragDropView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    FloatingActionMenu fam = new FloatingActionMenu(context);
    dragDropView.AddDraggableView(mainFM, 50, 50, RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    llContainerMain.addView(dragDropView);

如果有人能帮我解决这个问题,我会非常感激,如果有什么事情不清楚,我会很抱歉,我的英语不好,我会很抱歉

什么是“不起作用”的意思?它假设它拖放,但当我触摸listner时,它没有拖动什么是“不起作用”的意思?它假设它拖放,但当我触摸listner时,它没有拖动