Robert Valentino Well-Known Member Licensed User Longtime User Sep 13, 2018 #1 I have a floating keyboard on the screen and want to know if it is covering any part of another field I have on the screen. Sure I have seen a post of something like this, but I must be searching wrong. Does anyone have a routine that detects if on field (View) is overlaying any part of another field (View) BobVal
I have a floating keyboard on the screen and want to know if it is covering any part of another field I have on the screen. Sure I have seen a post of something like this, but I must be searching wrong. Does anyone have a routine that detects if on field (View) is overlaying any part of another field (View) BobVal
Semen Matusovskiy Well-Known Member Licensed User Sep 13, 2018 #2 Let's name Left1, Top1, Width1, Height1 for first view. The second view - Left2, Top2, Width2, Height2 . Easy to understand when views do not cover each other. 1) Horizontal direction: (Left1 + Width1) <= Left2 or (Left2 + Width2) <= Left1 2) Vertical direction: (Top1 + Height1) <= Top2 or (Top2 + Height2) <= Top1 So, common formula: Code: Copy If (((Left1 + Width1) <= Left2) Or ((Left2 + Width2) <= Left1)) And (((Top1 + Height1) <= Top2) Or ((Top2 + Height2) <= Top1)) Then ' Do not cover each other Width / height (for example, Panel1.Width, Button1.Height) are absolute. Left and top are relative. For example, Panel1 is a child of Activity. Panel1.Left = 50dip. Button1 is a child of Panel1. Button1.Left = 70dip (relative to Panel1). For our calculations we need absolute left (120dip). To retrieve left/top screen coordinates it's possible to add inline java Code: Copy #If Java import android.view.View; public int getScreenLocationX (View view) { int [] location = new int [2]; view.getLocationOnScreen (location); return (location [0]); } public int getScreenLocationY (View view) { int [] location = new int [2]; view.getLocationOnScreen (location); return (location [1]); } #End If and to use (for example) Code: Copy Sleep (0) ' Wait, if you resize/move inside this subroutine Dim jo As JavaObject jo.InitializeContext Left1 = jo.RunMethod ("getScreenLocationX", Array (Button1))) Top1 = jo.RunMethod ("getScreenLocationY", Array (Button1))) Upvote 0
Let's name Left1, Top1, Width1, Height1 for first view. The second view - Left2, Top2, Width2, Height2 . Easy to understand when views do not cover each other. 1) Horizontal direction: (Left1 + Width1) <= Left2 or (Left2 + Width2) <= Left1 2) Vertical direction: (Top1 + Height1) <= Top2 or (Top2 + Height2) <= Top1 So, common formula: Code: Copy If (((Left1 + Width1) <= Left2) Or ((Left2 + Width2) <= Left1)) And (((Top1 + Height1) <= Top2) Or ((Top2 + Height2) <= Top1)) Then ' Do not cover each other Width / height (for example, Panel1.Width, Button1.Height) are absolute. Left and top are relative. For example, Panel1 is a child of Activity. Panel1.Left = 50dip. Button1 is a child of Panel1. Button1.Left = 70dip (relative to Panel1). For our calculations we need absolute left (120dip). To retrieve left/top screen coordinates it's possible to add inline java Code: Copy #If Java import android.view.View; public int getScreenLocationX (View view) { int [] location = new int [2]; view.getLocationOnScreen (location); return (location [0]); } public int getScreenLocationY (View view) { int [] location = new int [2]; view.getLocationOnScreen (location); return (location [1]); } #End If and to use (for example) Code: Copy Sleep (0) ' Wait, if you resize/move inside this subroutine Dim jo As JavaObject jo.InitializeContext Left1 = jo.RunMethod ("getScreenLocationX", Array (Button1))) Top1 = jo.RunMethod ("getScreenLocationY", Array (Button1)))
Robert Valentino Well-Known Member Licensed User Longtime User Sep 14, 2018 #3 I had just converted some old C++ code to do this (new I saw or had it somewhere). Will give what you suggested a look see. Thanks Upvote 0
I had just converted some old C++ code to do this (new I saw or had it somewhere). Will give what you suggested a look see. Thanks