I'm trying to build an activity that has a checkbox on top, a button at the bottom, and a bunch of other widgets scrolling in between. Conceptually that's
LinearLayout CheckBox ScrollView LinearLayout [stuff] LinearLayout-end ScrollView-end Button LinearLayout-endWhen it renders I get the checkbox at the top, the stuff scrolling nicely underneath, but the Button drawn offscreen (I assume) below the ScrollView. The only way I can get the Button to be visible is to hard-code the height of the ScrollView, which of course only works on one screen-size. I've tried all combinations of gravity and layout_weight I can think of to no avail. Am I using the right combination of Views? Anybody managed to get this working?
(I don't think 开发者_JAVA百科RelativeLayout is quite the right container for this, but regardless I hope to avoid it since it's broken on 1.5.)
Thanks,
--Eric
I had the same problem recently and I added:
<ScrollView
...
android:layout_weight="1" >
that solved my problem.
I've used this in 2.2, not sure if the layout_above and layout_below tags are available in 1.5 (if thats what your using). Layout your three main elements, the header, the footer and your central content (in this case a list view) that you want to fill the remaining area with.
You could replace the Listview with a scrollView if you wanted, or any component for that matter.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<Button
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Top Button"/>
<Button
android:id="@+id/footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Button"/>
<ListView
android:id="@android:id/center"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/header"
android:layout_above="@id/footer"/>
</RelativeLayout>
Note the order of your elements. Not sure its relevant but the center element is defined last.
精彩评论