Search code examples
androidlayoutfixed

How do I fix a layout at bottom and at top without hiding elements on Android?


I'm having problems when using RelativeLayout, ScrollView and some LinearLayout to get some elements always on top and something scrollable.

This is my XML

https://pastebin.com/Uai2UynP

(I don't know why it got separated in this post but it's the same code) The point is, when i add the android:alignParentBottom="true" to the RelativeLayout with the "always on top bar", it hides me a part of the ScrollView above. This can be solved adding a android:PaddingBottom="[something]" to the ScrollView above, but doing this it hides me something at the top, since I basically have the LinearLayout with email, gold and coin that i want too always on top.


Solution

  • Use RelativeLayout as main layout and use android:layout_alignParentTop="true" in your layout which you want to place top and use android:layout_alignParentBottom="true" in your next layour which you want to set bottom of your layout. I am giving you a Example,

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
    
            <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
            android:layout_alignParentTop="true">
    
    
        </RelativeLayout>
    
    
        <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
            android:layout_alignParentBottom="true">
    
        </RelativeLayout>
    
    </RelativeLayout>