diff --git a/.gitignore b/.gitignore index dfee9d9e..853deedd 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ .externalNativeBuild .cxx /check/detekt/reports -.idea \ No newline at end of file +.idea*.class +META-INF/ diff --git a/com/petterp/floatingx/assist/FxAdsorbDirection.class b/com/petterp/floatingx/assist/FxAdsorbDirection.class new file mode 100644 index 00000000..5ef051d6 Binary files /dev/null and b/com/petterp/floatingx/assist/FxAdsorbDirection.class differ diff --git a/com/petterp/floatingx/assist/FxBorderMargin.class b/com/petterp/floatingx/assist/FxBorderMargin.class new file mode 100644 index 00000000..e857b2d8 Binary files /dev/null and b/com/petterp/floatingx/assist/FxBorderMargin.class differ diff --git a/com/petterp/floatingx/assist/FxBoundaryConfig.class b/com/petterp/floatingx/assist/FxBoundaryConfig.class new file mode 100644 index 00000000..b68c55ca Binary files /dev/null and b/com/petterp/floatingx/assist/FxBoundaryConfig.class differ diff --git a/com/petterp/floatingx/assist/FxDisplayMode.class b/com/petterp/floatingx/assist/FxDisplayMode.class new file mode 100644 index 00000000..04872d40 Binary files /dev/null and b/com/petterp/floatingx/assist/FxDisplayMode.class differ diff --git a/com/petterp/floatingx/assist/FxScopeType.class b/com/petterp/floatingx/assist/FxScopeType.class new file mode 100644 index 00000000..b70f734f Binary files /dev/null and b/com/petterp/floatingx/assist/FxScopeType.class differ diff --git a/com/petterp/floatingx/listener/IKeyBackListener.class b/com/petterp/floatingx/listener/IKeyBackListener.class new file mode 100644 index 00000000..346fde48 Binary files /dev/null and b/com/petterp/floatingx/listener/IKeyBackListener.class differ diff --git a/com/petterp/floatingx/listener/control/IFxSystemControl.class b/com/petterp/floatingx/listener/control/IFxSystemControl.class new file mode 100644 index 00000000..51ac8531 Binary files /dev/null and b/com/petterp/floatingx/listener/control/IFxSystemControl.class differ diff --git a/floatingx/src/main/java/com/petterp/floatingx/view/helper/FxViewLocationHelper.kt b/floatingx/src/main/java/com/petterp/floatingx/view/helper/FxViewLocationHelper.kt index 85f394b6..10435d52 100644 --- a/floatingx/src/main/java/com/petterp/floatingx/view/helper/FxViewLocationHelper.kt +++ b/floatingx/src/main/java/com/petterp/floatingx/view/helper/FxViewLocationHelper.kt @@ -79,11 +79,16 @@ class FxViewLocationHelper : FxViewBasicHelper(), View.OnLayoutChangeListener { } override fun onSizeChanged(w: Int, h: Int, oldW: Int, oldH: Int) { - updateViewSize() + val sizeChanged = updateViewSize() // 初始化跳过 if (isInitLocation) return if (needUpdateLocation) { checkOrRestoreLocation() + } else if (sizeChanged && !config.gravity.isDefault()) { + // 当View大小改变且设置了非默认Gravity时,根据Gravity重新计算位置 + val (newX, newY) = recalculatePositionByGravity() + basicView?.internalMoveToXY(newX, newY) + config.fxLog.d("fxView -> onSizeChanged: recalculated position by gravity, x:$newX, y:$newY") } else { basicView?.internalMoveToXY(safeX(x), safeY(y)) } @@ -196,21 +201,22 @@ class FxViewLocationHelper : FxViewBasicHelper(), View.OnLayoutChangeListener { } } - private fun updateViewSize() { - val view = basicView ?: return - val (pW, pH) = view.parentSize() ?: return + private fun updateViewSize(): Boolean { + val view = basicView ?: return false + val (pW, pH) = view.parentSize() ?: return false val viewH = view.height.toFloat() val viewW = view.width.toFloat() // 如果大小没有变化,则不更新 if (this.parentW == pW.toFloat() && this.parentH == pH.toFloat() && this.viewW == viewW && this.viewH == viewH - ) return + ) return false this.parentW = pW.toFloat() this.parentH = pH.toFloat() this.viewW = viewW this.viewH = viewH updateMoveBoundary() config.fxLog.d("fxView -> updateSize: parentW:$parentW,parentH:$parentH,viewW:$viewW,viewH:$viewH") + return true } private fun isNearestLeft(x: Float): Boolean { @@ -268,6 +274,14 @@ class FxViewLocationHelper : FxViewBasicHelper(), View.OnLayoutChangeListener { } } + /** + * 根据当前Gravity设置重新计算位置 + * 当View大小改变时,根据Gravity重新定位 + */ + private fun recalculatePositionByGravity(): Pair { + return getDefaultXY(parentW, parentH, viewW, viewH) + } + internal fun updateMoveBoundary() { config.apply { // 如果启用了半隐藏,这里需要单独处理