2

I've implemented a DrawerLayout in my application's primary XML layout - and I've created a footer (basically a horizontal [navigation-ish] bar) which fill the bottom of the screen. The problem is - it is continually appearing at the top of the screen... I've attempted using android:layout_gravity="bottom", android:layout_weight="1.0" and android:baselineAligned="false" as documented here: http://sandipchitale.blogspot.com/2010/05/linearlayout-gravity-and-layoutgravity.html However I still cannot seem to get the footer from appearing at the top of the layout.

Any suggestions are appreciated:

XML Snippet:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="bottom"
    android:background="@color/black"
    android:baselineAligned="false" >



    ...



        <LinearLayout
        android:id="@+id/footer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1.0"
        android:orientation="horizontal" >
    </LinearLayout>

</android.support.v4.widget.DrawerLayout>

Full XML Source:

http://pastebin.com/67cHtwJ1

Screenshot:

enter image description here

1 Answers1

6

You should be applying layout_gravity:bottom to the LinearLayout, not the DrawerLayout. The layout_ prefix lets the child tell the parent how it would like to be laid out, positioned, etc. android:gravity should be applied to a parent view and is used to position all of its children.

NasaGeek
  • 2,138
  • 1
  • 15
  • 19
  • I attempted your solution and ended up with: ava.lang.IllegalStateException: Child android.widget.LinearLayout{422112e0 V.E..... ......I. 0,0-0,0 #7f0800ab app:id/footer} at index 7 does not have a valid layout_gravity - must be Gravity.LEFT, Gravity.RIGHT or Gravity.NO_GRAVITY - any suggestions? http://pastebin.com/hXRPnUHy (thank you for your assistance [btw - I love the username - I have two generations of family members who work at NASA]) – AndroidAndroidAndroid Sep 29 '15 at 19:55
  • I'm looking at the code a bit closer to see what else I might be able to do... (I appreciate your insight regardless) :) – AndroidAndroidAndroid Sep 29 '15 at 20:14
  • AhhHa! I needed to wrap it in a RelativeLayout and assign android:layout_alignParentBottom="true" - but I finally got it to work - thank you Sir! (<- I think) ;) – AndroidAndroidAndroid Sep 29 '15 at 20:19
  • 1
    Interesting. It seems like DrawerLayout doesn't like seeing children with a `layout_gravity` of anything besides left or right. `RelativeLayout` doesn't sound like a bad solution, though. You might not want to mark my solution as accepted, though, since it didn't actually solve your problem ;) – NasaGeek Sep 29 '15 at 20:51
  • Also, I believe you should be placing your main content within the "content_frame" `FrameLayout` rather than after your `ListView`. Study this article to get a better idea of how the `DrawerLayout` should be structured. https://developer.android.com/training/implementing-navigation/nav-drawer.html – NasaGeek Sep 29 '15 at 20:53