Git Product home page Git Product logo

Comments (4)

princekin-f avatar princekin-f commented on June 1, 2024
  • 获取相对于父控件的坐标:FloatingView.getX()FloatingView.getY(),此时是视觉上的相对于父控件的位置,是原始坐标加上偏移量。
  • FloatingView.getX() = getLeft() + getTranslationX()
  • FloatingView.getY() = getTop() + getTranslationY()

更多内容你可以参考issues 12里面的文章。

from easyfloat.

roybill avatar roybill commented on June 1, 2024

请问有没有办法可以直接拿到拖动时每次变化的xy轴坐标值?就类似这个库https://github.com/yhaolpz/FloatWindow的回调函数 public void onPositionUpdate(int x, int y) {
mXLocation.setText(String.valueOf(x));
mYLocation.setText(String.valueOf(y));
//todo:最终的x, y轴坐标
Log.d(TAG, "1555 onPositionUpdate: x=" + x + " y=" + y);
}
如果还要我们使用者再花很多时间去获取这些值,那就失去了封装这个库的意义了吧?

from easyfloat.

princekin-f avatar princekin-f commented on June 1, 2024
  • 你所说的拖拽时每次变化的值是什么,是拖拽过程的坐标信息?还是拖拽结束的坐标信息?
  • 如果是上面所说的两种数据,可以使用标准格式,里面的Callback都有实现:
    // ps:通过Kotlin DSL实现的回调,可以按需复写方法,用到哪个写哪个
    .registerCallback {
        createResult { isCreated, msg, view ->  }
        show {  }
        hide {  }
        dismiss {  }
        touchEvent { view, motionEvent ->  }
        drag { view, motionEvent ->  }
        dragEnd {  }
    }

在Java中使用Kotlin DSL不是很方便,状态回调还有一种常规的接口方式:

.registerCallbacks(new OnFloatCallbacks() {
        @Override
        public void createdResult(boolean isCreated, @Nullable String msg, @Nullable View view) { }

        @Override
        public void show(@NotNull View view) { }

        @Override
        public void hide(@NotNull View view) { }

        @Override
        public void dismiss() { }

        @Override
        public void touchEvent(@NotNull View view, @NotNull MotionEvent event) { }

        @Override
        public void drag(@NotNull View view, @NotNull MotionEvent event) { }

        @Override
        public void dragEnd(@NotNull View view) { }
})
  • 建议您先看一下文档或者demo,毕竟别人的时间也是宝贵的!

from easyfloat.

roybill avatar roybill commented on June 1, 2024

谢谢,我是这样拿的,再用你的方法优化试试
FloatingView floatingView = findViewById(R.id.floatingView);
floatingView.setOnTouchListener(new View.OnTouchListener() {
@OverRide
public boolean onTouch(View v, MotionEvent event) {
float xValue = v.getX(); //拖动时的坐标值
float yValue = v.getY();
finalX = xValue;
finalY = yValue;
mX.setText(String.valueOf(finalX));
mY.setText(String.valueOf(finalY));
LogUtil.d("1527 x=" + xValue + " y=" + yValue);
return Yiyilingqi.super.onTouchEvent(event);
}
});

from easyfloat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.