F0x1d / LogFox

Yet another LogCat reader for Android
GNU General Public License v3.0
605 stars 32 forks source link

[FR] Disable automatic scrolling of ScrollView due to changes in focus #107

Closed Jesse205 closed 8 months ago

Jesse205 commented 8 months ago

https://github.com/F0x1d/LogFox/assets/51242302/51d8a985-8710-4e67-811d-07a5b7a1678b

Translated from Baidu Translate

In Android, if textIsSelectable is set to TextView, it will automatically enable focusInTouchMode. (Although this may not be entirely reasonable, the fact is that it is.)

And in Android, if a View gains focus, Android will view it to display it fully on the screen.

This creates a situation in the video where when long pressing the selection button, ScrollView will immediately scroll to the position of TextView, causing a decrease in user experience (selecting multiple unrelated lines of text and potentially confusing the user).

In traditional android.widget.ScrollView, we only need to set 'setRevealOnFocusHint' to TextView, but this value does not work when using NestedScrollView because NestedScrollView was not evaluated during implementation.

So we need to use other methods. That is, after inheriting NestedView, rewrite the computeScrollDeltaToGetChildRectOnScreen method and return 0. I have tested in another project and it will work.

Translated from ERNIE Bot

In Android, when the textIsSelectable property is enabled for a TextView, the focusInTouchModeis automatically activated. This may seem counterintuitive, but it's the actual behavior.

Additionally, in Android, when a View gains focus, the system assumes it needs to be fully visible on the screen.

This can lead to the issue described in the video, where upon long-pressing a TextView, the ScrollView immediately scrolls to the position of the TextView, potentially degrading the user experience (as multiple lines of text may be unintentionally selected during the long-press, leading to confusion).

In the traditional android.widget.ScrollView, one workaround for this issue is to set the setRevealOnFocusHint property of the TextView to true. However, when using NestedScrollView, this workaround does not work as NestedScrollView does not take this property into account during its implementation.

Therefore, an alternative approach is necessary. One such approach is to inherit from NestedScrollView and override the computeScrollDeltaToGetChildRectOnScreen method, returning 0. I have tested this approach in another project, and it resolves the issue.

Related links

https://blog.csdn.net/ZYJWR/article/details/108386309