I have an activity that has a header at the top开发者_StackOverflow中文版 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
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>
If you didn't want to switch to a RelativeLayout,
I would think you could use android:layout_weight
attributes to distribute screen real estate.
So in this case, you want to have Header(Top), scrollview(middle) and Buttons(Bottom), for this just take a RelativeLayout.
精彩评论