mardi 12 mai 2015

ScrollView not sizing itself correctly

I'm trying to get a ScrollView to take up as much screen space as it needs until it would start pushing items below (outside) it off the screen, then it needs to stop expanding and become scrolly.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" 
>

    <ScrollView 
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="#ff0000"
    >
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="taking\nup\lots\nof\nlines\nto\nmake\nthe\nscrollview&quot;s\ncontent\ntaller\nthan\nthe\nspace\navailable\nto\nit\nwhich\nshould\nmake\nthe\nscrollview\nstop\nabove\nthe\nbutton\nand\nbecome\nscrollable"
        /> 
        <!-- 
            android:text="just one line"
        -->
    </ScrollView>

    <Button
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="Button"
    />
</LinearLayout>

As it is above the ScrollView fills the entire screen height and pushes the button off the bottom of the screen. If I add android:layout_weight="1" to the ScrollView then it works for this case - the button is at the bottom and the ScrollView stops above it - but when the ScrollView doesn't have much content (replace the text with the one-liner) then the ScrollView doesn't shrink to fit around the content so is far too tall.

I've tried using RelativeLayout with no success - if the Button is android:layout_below the ScrollView then the ScrollView will push it off the bottom of the screen if it has a lot of content.

Aucun commentaire:

Enregistrer un commentaire