Fixed a bug in relative margins on Android #1035
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
summary
When doing SetMargins with relative true on android, the margins are incorrect.
On Android, Screen.width(height) always returns the same value as Screen.currentResolution.width(height).
So, whether relative is true or false, ml, mt, mr, and mb use the same value.
unity-webview/plugins/WebViewObject.cs
Lines 824 to 841 in 09f1925
Display.main.systemWidth(systemHeight) can be used to obtain the resolution of the physical screen.(not rendering resolution)
The argument of ViewGroup.MarginLayoutParams.setMargin, which is executed in CWebViewPlugin.java, uses px.(physical screen)
So I think this bug can be fixed by using Display.main.systemWidth(systemHeight).
unity-webview/plugins/Android/webview/src/main/java/net/gree/unitywebview/CWebViewPlugin.java
Line 1069 in 09f1925
How to reproduce
You can reproduce the bug by calling WebViewObject.SetMargins after using Screen.SetResolution on Android.
Display.main.systemWidth(systemHeight) instead of Screen.currentResolution.width(height) seems to correctly convert from the value on the rendering resolution to the value on the physical resolution(px).
cf
https://docs.unity3d.com/ScriptReference/Display-systemWidth.html
https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams#attr_android:layout_margin
https://docs.unity3d.com/ScriptReference/Screen.SetResolution.html