Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I get an Android view to take up "remaining" space?

I have an activity that has a header at the top of the screen, some button elements at the bottom of the screen and then I'd like to devote the middle (whatever is left over) to a scroll view.

I know how to do everything except for how to assign a height to the ScrollView that would take into account what is above and below it and then take residence in between.

Would love to see an XML sample for how to accomplish this effect.

TIA

like image 502
Yevgeny Simkin Avatar asked Feb 02 '26 03:02

Yevgeny Simkin


1 Answers

You can use relative layout for this.

<RelativeLayout android:layout_width="fill_parent"
                android:layout_height="fill_parent">
  <LinearLayout android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:id="@+id/header">
    <!--Header elements here-->
  </LinearLayout>
  <LinearLayout android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:alignParentBottom="true"
                android:id="@+id/footer">
    <!--Footer element here-->
  </LinearLayout>
  <ScrollView android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:layout_above="@+id/footer"
              android:layout_below="@+id/header">
  </ScrollView>
</RelativeLayout>
like image 179
Rahul Choudhary Avatar answered Feb 04 '26 22:02

Rahul Choudhary



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!