简体   繁体   中英

Prevent Scrollview to overlap with other views in RelativeLayout in Android

I want to have a Layout with 3 sections: header, content and footer in which the header and footer sections should stay fixed on top and at the bottom of the screen respectively. The content section in the middle is dynamic and can grow very long. In that case, I want it to be scrollable and still fit in the middle. So I tried something like this:

<RelativeLayout...>
<LinearLayout android="@+id/header"
android:layout_alignParentTop="true"
..../>
<ScrollView android:id="@+id/content"
android:layout_below="@id/header"
android:layout_above="@+id/footer"
...>
<LinearLayout
.../>
</ScrollView>
<LinearLayout android="@id/footer"
android:layout_alignParentBottom="true"
.../>
</RelativeLayout>

However when the content is long, the middle section grow and overlap with header and footer. Does anyone has a better idea on how to achieve this?

Finally, I achieved this by wrapping the ScrollView inside another LinearLayout. It seems redundant, but well it works. ScrollView seems does not play well with other LinearLayout inside RelativeLayout. Below are the codes:

<RelativeLayout...>
<LinearLayout android="@+id/header"
android:layout_alignParentTop="true"
..../>
<LinearLayout android:layout_below="@id/header"
android:layout_above="@+id/footer"
...>
<ScrollView ...
>
<LinearLayout android:id="@+id/content"
.../>
</ScrollView>
</LinearLayout>
<LinearLayout android="@id/footer"
android:layout_alignParentBottom="true"
.../>
</RelativeLayout>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM