Android ScrollView jumps when resizing

I have a ScrollView that contains several other views (TextViews, ImageViews, etc.). ScrollView above the screen. I have an AsyncTask that updates ScrollView child elements based on an HTTP response.

I found an interesting behavior that I cannot figure out how to work. If I set any of the children's visions to View.INVISIBLE as part of AsyncTask.onPostExecute (), everything will be fine.

However, if I set any visibility for children in View.GONE, the ScrollView is reset from above when onPostExecute () is called. Just how far seems to be changing. I assume that re-laying the ScrollView causes it to scroll on top for some reason.

So the question is: is there a way to prevent or circumvent this behavior?

PS. Using ScrollView.jump (FOCUS_UP) as a workaround is not ideal, as it will force the user to go up, even if they intended to scroll down.

EDIT . Actually, I was wrong. The problem was not that the child view was marked as departed, the problem was that the marriage view was marked as departed, and ScrollView received a resize. My ScrollView is inside a LinearLayout, which also contains a button. When the button is set to GONE, ScrollView will change to take up free space, as a result of which it will scroll from the top. Another reason is still looking for a workaround if possible.

+3
source share
1

. ,

android:descendantFocusability="blocksDescendants"

:

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants" >
+2

Source: https://habr.com/ru/post/1750185/


All Articles