Comments (4)
- 获取相对于父控件的坐标:
FloatingView.getX()
,FloatingView.getY()
,此时是视觉上的相对于父控件的位置,是原始坐标加上偏移量。 FloatingView.getX() = getLeft() + getTranslationX()
FloatingView.getY() = getTop() + getTranslationY()
更多内容你可以参考issues 12里面的文章。
from easyfloat.
请问有没有办法可以直接拿到拖动时每次变化的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.
- 你所说的拖拽时每次变化的值是什么,是拖拽过程的坐标信息?还是拖拽结束的坐标信息?
- 如果是上面所说的两种数据,可以使用标准格式,里面的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.
谢谢,我是这样拿的,再用你的方法优化试试
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)
- 调用setBorder右边的边界值无效
- 添加依赖后没有EasyFloat类
- 悬浮窗内添加ListView后ListView无法上下滑动
- 会挡住输入法 可以怎么解决吗?
- 希望可以自己配置WindowManager.LayoutParams.flags ,需要不拦截遮挡底部的点击事件
- 浮窗中的EditText无法弹起软键盘
- 请问只想要在部分页面展示悬浮窗应该怎么设置?
- ParentFrameLayout not attached to window manager
- 长按EditText中的文字,无法弹出复制剪切的ContextMenu HOT 1
- FloatingWindowHelper中设置config.layoutView和config.layoutId处理逻辑不一致,导致在使用setFilter时需要手动显示view
- 错误: 程序包com.lzf.easyfloat.widget.activityfloat不存在
- This feature requires ASM6
- 内存泄露 HOT 1
- 多进程应用使用会出现 Only the original thread that created a view hierarchy can touch its views HOT 1
- 嵌套recyclerView并开启拖动,会导致recyclerView本身滑动失效 HOT 1
- 通过发通知方式通知另外一个Activity显示浮窗,设置的偏移量失效
- EasyFloat.with(activity)建议
- 你好,悬浮窗其中自带的申请浮窗权限,自动处理回调结果失效 HOT 1
- 建议添加图层优先级显示设置
- 横向模式下面、沉浸模式,吸附模式无法吸附到上方
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from easyfloat.