From 04ca9b7833138f5e5a4da4511297bd181db9cdbe Mon Sep 17 00:00:00 2001 From: cgspine Date: Tue, 16 Mar 2021 22:45:03 +0800 Subject: [PATCH] use parent size if self size is zero. --- .../qmuiteam/qmui/arch/SwipeBackLayout.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arch/src/main/java/com/qmuiteam/qmui/arch/SwipeBackLayout.java b/arch/src/main/java/com/qmuiteam/qmui/arch/SwipeBackLayout.java index 26c21129..d06805b3 100644 --- a/arch/src/main/java/com/qmuiteam/qmui/arch/SwipeBackLayout.java +++ b/arch/src/main/java/com/qmuiteam/qmui/arch/SwipeBackLayout.java @@ -816,21 +816,45 @@ public class SwipeBackLayout extends FrameLayout { public float getXFraction() { int width = getWidth(); + if(width == 0){ + ViewParent parent = getParent(); + if(parent instanceof ViewGroup){ + width = ((ViewGroup)parent).getWidth(); + } + } return (width == 0) ? 0 : getX() / (float) width; } public void setXFraction(float xFraction) { int width = getWidth(); + if(width == 0){ + ViewParent parent = getParent(); + if(parent instanceof ViewGroup){ + width = ((ViewGroup)parent).getWidth(); + } + } setX((width > 0) ? (xFraction * width) : 0); } public float getYFraction() { int height = getHeight(); + if(height == 0){ + ViewParent parent = getParent(); + if(parent instanceof ViewGroup){ + height = ((ViewGroup)parent).getHeight(); + } + } return (height == 0) ? 0 : getY() / (float) height; } public void setYFraction(float yFraction) { int height = getHeight(); + if(height == 0){ + ViewParent parent = getParent(); + if(parent instanceof ViewGroup){ + height = ((ViewGroup)parent).getHeight(); + } + } setY((height > 0) ? (yFraction * height) : 0); }