Scrollbars in ScrollView not showing after custom child view changes size
Posted
by
Ted Hopp
on Stack Overflow
See other posts from Stack Overflow
or by Ted Hopp
Published on 2011-01-05T04:46:44Z
Indexed on
2011/01/05
4:54 UTC
Read the original article
Hit count: 282
I have a ScrollView containing a client that is a vertical LinearLayout. The client, in turn, contains custom views that change height dynamically as a background thread does some work. The problem I'm having is that the ScrollView's vertical scroll bar is not updating correctly in Android 1.5. The most common problem occurs when the initial total height of the client is less than the viewport and grows. Initially there is no scroll bar, and it does not show up when the client grows until I actually scroll the window with a touch gesture or other UI action. After that, the scroll bar shows up. However, the thumb does not update as the height continues to change from the background thread. If I scroll the view again through the UI, the thumb immediately corrects itself. My code for updating the height from the background thread is:
post(mLayoutRequestor);
postInvalidate();
(mLayoutRequestor is a Runnable that just calls requestLayout().) This is done after I've recorded the new height in a variable mHeight. My onMeasure() method calls setMeasuredDimension with a height computed like this:
private int measureHeight(int measureSpec) {
int result;
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
if (specMode == MeasureSpec.EXACTLY) {
result = specSize;
} else {
result = mHeight;
if (specMode == MeasureSpec.AT_MOST && result > specSize)
result = specSize;
}
return result;
}
Am I supposed to be calling something else besides requestLayout() to get the scroll bar to update correctly?
© Stack Overflow or respective owner