I am trying to get a quite simple layout in Android, but I just can't get it to work. All I want is a header (by include an XML file), followed by a ScrollView to show a large body of text, and two buttons in the bottom, that should always be visible.
I have fiddled with LinearLayouts and RelativeLayouts, but somehow, I can't get it to work. What I have until now is this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include layout="@layout/header" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ScrollView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/svDisclaimer"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/tvDisclaimer">
</TextView>
</ScrollView>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/svDisclaimer"
>
.. [ snip ] ..
</LinearLayout>
</RelativeLayout>
</LinearLayout>
( .. [snip] .. is where my buttons are) The header is there, the scrollview pops up, but the buttons are nowhere to be seen.
Your ScrollView's height is set to fill_parent which pushes everything below the ScrollView off the bottom of the screen. You will never see what you cannot scroll to... try this pattern instead:
<ScrollView >
<RelativeLayout >
<TextView />
<LinearLayout >
<!-- [ snip ] -->
</LinearLayout>
</RelativeLayout>
</ScrollView>
You can probably remove the LinearLayout by using the RelativeLayout position tags as well. (android:below, android:toRightOf, etc)
Try using this configuration from my comment:
<ScrollView
...
android:above="@+id/buttons" >
...
</ScrollView>
<LinearLayout
android:id="@+id/buttons"
android:layout_alignParentBottom="true"
... >
...
</LinearLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With