How to change size of Android ScrollView

∥☆過路亽.° 提交于 2019-12-22 09:13:33

问题


I have a layout like this (abstracted):

Scrollview - fill_parent

LinearLayout - wrap_content

ImageView 1 - wrap_content

ImageView 2 - ...

ImageView 3

...

In the course of user interaction some images are replaced by larger or smaller ones, shortening or lenghtening the area to be scrolled. And that is the problem. The Scrollview (SV) does not know about the change, so either it scrolls over a lot of empty space at the bottom, or cuts off a picture or two at the bottom.

Question 1: Can I somehow make the SV readapt to the changed hight of the LiearLayout (LL)?

Question 2: I can obtain the current size through getHight on the LL. But supplyong it to the SV via changed LayoutParams does not work - of course, that would only change the height of the SV on the screen. Is there a way to put the changed height of the LL into the SV in the code, somehow?

Question 3: I havn't tried it yet. Would creating the SV, LL and its children in code and then adding/removing children of changed size as required, make the SV adapt to the changes?

And last question: Is there a better aüpproach, except using ListViews?


回答1:


Have you tried calling requestLayout() when images change?



来源:https://stackoverflow.com/questions/4963866/how-to-change-size-of-android-scrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!