Rectangle 27 0

android buttons below expanding scrollview?


private void setMargins_noKeyboard()
{
    ScrollView fieldsScroller = (ScrollView)findViewById(R.id.scroll_fields_view);
    FrameLayout keyboardFrame = (FrameLayout)findViewById(R.id.keyboard_root);
    int buttonsKeyboardSize = keyboardFrame.getHeight();

    MarginLayoutParams frameParams = (MarginLayoutParams)keyboardFrame.getLayoutParams();
    frameParams.setMargins(0, 0, 0, 0);

    MarginLayoutParams scrollParams = (MarginLayoutParams)fieldsScroller.getLayoutParams();
    scrollParams.setMargins(0, 0, 0, 0);

    keyboardFrame.setLayoutParams(frameParams);
    fieldsScroller.setLayoutParams(scrollParams);
}

private void setMargins_keyboard()
{
    ScrollView fieldsScroller = (ScrollView)findViewById(R.id.scroll_fields_view);
    FrameLayout keyboardFrame = (FrameLayout)findViewById(R.id.keyboard_root);
    int buttonsKeyboardSize = keyboardFrame.getHeight();

    MarginLayoutParams frameParams = (MarginLayoutParams)keyboardFrame.getLayoutParams();
    frameParams.setMargins(0, -buttonsKeyboardSize, 0, 0);

    MarginLayoutParams scrollParams = (MarginLayoutParams)fieldsScroller.getLayoutParams();
    scrollParams.setMargins(0, 0, 0, buttonsKeyboardSize);

    keyboardFrame.setLayoutParams(frameParams);
    fieldsScroller.setLayoutParams(scrollParams);
}

After working with this quite a bit more, I have found that while the above answer works there is a better solution. Using a relative layout works very reliably without all the programatic gyrations of this answer. The key is at least one element that aligns with parent top and one element that aligns with parent bottom. The rest of the elements align relative to these two, the scrollview ultimately is sandwiched between anything that needs to remain stationary.

I have some very specific customized needs for a keyboard solution -- requiring me to handle the display and tear-down of the keyboard on my own as a z-layer element in a frameLayout. I use the solution in that link to accomplish that and change the size of the scrollView at the same time. The buttons in the scroll view move from flush with the bottom of the screen to flush with the top of the keyboard.

The key is having android:fillViewport="true" on the scrollView. Then programmatically setting the bottom margin of the scrollView to and the top margin of the bottom element to -height.

Note
Rectangle 27 0

android buttons below expanding scrollview?


<LinearLayout 
   android:layout_height="wrap_content" 
   orientation="vertical"...>
   <ScrollView
      android:layout_height="0dp"
      android:layout_weight="1"
      .../>
   <LayoutWithButtons
      android:layout_height="wrap_content"
      ..../>
</LinearLayout>

Hmm, what happens if you set the outer LinearLayout to wrap_content? If that doesn't work on its own, wrap it in another LinearLayout with a greedy (height=0, weight=1) invisible element below it?

I'm getting an error that layout_height="0" is not a valid value, but using wrap_content seems to work perfectly.

If that's the case, you can use a LinearLayout at the outer level and make use of weights:

Is the goal just to have a scrollable area that takes up the entire page minus the amount taken up by some buttons at the bottom?

It still expands and pushes the buttons out of the screen...

Setting the outer Layout with wrap_content worked. If I add the other greedy invisible Layout, the buttons would be stuck in the middle of the screen. But you got it.. thanks !

Sorry, I guess it was not clear... added a sketch...

Note
Rectangle 27 0

android buttons below expanding scrollview?


android:fillViewport="true"

IN the first case (when there is not many items in the list), then the scrollview would fill the whole screen which is NOT what I want...

This should be the answer in xml

Note