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.
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 enablefocusInTouchMode
. (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 usingNestedScrollView
becauseNestedScrollView
was not evaluated during implementation.So we need to use other methods. That is, after inheriting
NestedView
, rewrite thecomputeScrollDeltaToGetChildRectOnScreen
method and return0
. 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, thefocusInTouchMode
is 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 thesetRevealOnFocusHint
property of the TextView to true. However, when usingNestedScrollView
, this workaround does not work asNestedScrollView
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 thecomputeScrollDeltaToGetChildRectOnScreen
method, returning0
. I have tested this approach in another project, and it resolves the issue.Related links
https://blog.csdn.net/ZYJWR/article/details/108386309