如何用onTouchListener改变fab的位置?

时间:2016-08-12 15:56:56

标签: android floating-action-button

我正在使用浮动操作按钮。当用户触摸晶圆厂并拖动它时,我想改变晶圆厂的位置。我正在使用onTouchListener,但它不能很好地移动工厂。 这是我的代码:

final FloatingActionButton fabButton = new FloatingActionButton.Builder(this)
    .withDrawable(getResources().getDrawable(R.drawable.fab))
    .withButtonColor(Color.WHITE)
    .withGravity(Gravity.BOTTOM | Gravity.RIGHT)
    .withMargins(0, 0, 16, 16)
    .create();
    fabButton.setAlpha(0.6f);
    fabButton.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            fabButton.setX(event.getX());
            fabButton.setY(event.getY());

            return false;
        }
    });

提前感谢任何建议......

0 个答案:

没有答案
相关问题