appd3vs
appd3vs

Reputation: 21

how to get my layout to be at the bottom of my activity

hello I am working on a ios styled app that has a layout out the bottom well I can't seem to get this layout in question to be at the bottom

here's my code:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="10"
    tools:context=".MyActivity"
    tools:ignore="UselessLeaf,ContentDescription" >


    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_marginBottom="5dp"
        android:layout_weight="7" >
    </android.support.v4.view.ViewPager>

    <com.viewpagerindicator.CirclePageIndicator
        android:id="@+id/pagerIndicator"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5"
        android:padding="3dp" />



        <LinearLayout
            android:id="@+id/layout11"
            android:layout_width="match_parent"
            android:layout_height="30dip"
            android:background="@drawable/dock"
             android:layout_gravity="bottom"
            android:orientation="horizontal" >

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center|bottom"
                tools:ignore="NestedWeights" >

                <ImageView
                    android:id="@+id/dial"
                    android:layout_width="wrap_content"
                    android:layout_height="10dp"
                    android:layout_gravity="center_horizontal|center"
                    android:src="@drawable/dialer"
                    tools:ignore="ContentDescription" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="bottom"
                android:layout_weight="1" >

                <ImageView
                    android:id="@+id/back"
                    android:layout_width="wrap_content"
                    android:layout_height="10dp"
                    android:layout_gravity="center_horizontal|center"
                    android:src="@drawable/back" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="center_horizontal|center"
                android:layout_weight="1" >

                <ImageView
                    android:id="@+id/sms"
                    android:layout_width="wrap_content"
                    android:layout_height="10dp"
                    android:layout_gravity="center_horizontal|center"
                    android:src="@drawable/mms" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="center_horizontal|center"
                android:layout_weight="1" >

                <ImageView
                    android:id="@+id/music"
                    android:layout_width="wrap_content"
                    android:layout_height="10dp"
                    android:src="@drawable/music"
                    android:visibility="gone" />
            </LinearLayout>
        </LinearLayout>





</LinearLayout>

here's what it looks like right now: IMAGE

I want the buttons at the bottom of the page

what am I doing wrong?

please let me know

thanks a million times over

Chris

Upvotes: 0

Views: 135

Answers (4)

Leo
Leo

Reputation: 14820

As Hesam's answer pointed out when you use the layout_weight attribute in your 2nd layout you should make the layout_height=0dp...if you're using Android Studio then it should be giving you a warning about it. However, I'd like to add to his answer that there's a lot of room for improvement in your layout file as a whole...and I mean A LOT!!! You've got what I call a spaguetti of useless nested layouts. To mention a few

  1. The 2nd LinearLayout is absolutely useless...it's empty, not needed
  2. The root LinearLayout can be easily converted to a RelativeLayout, then push the bottom-most child view to the bottom using layout_alignParentBottom=true and finally stack all other children on top of this bottom view using layout_above
  3. You have a lot nested LinearLayout with one single child...IMHO this is useless
  4. You have a lot nested RelativeLayout with one single child...IMHO this is useless as well

I could go on forever, but you really should address these nested layout issues because you are adding a lot of unnecessary overhead to your UI...this is pretty heavy man

Further recommendations based on the screenshot added

This what I would recommend

  • I'd recommend using a RelativeLayout as the root/top layout
  • Add a ListView to display all those images/icons and set the layout_alignParentTop=true with layout_height=wrap_content
  • Then add a LinearLayout below it with a horizontal orientation to display the buttons

Upvotes: 1

Petecocoon
Petecocoon

Reputation: 23

You can use a RelativeLayout instead of LinearLayout as a root layout and then set android:layout_alignParentBottom="true" to the bottom layout

Upvotes: 0

Carsten
Carsten

Reputation: 806

You could use a RelativeLayout as parent and then use alignParentBottom=“true” however I am not completely sure what you are trying to achieve i.e. how it should look like.

Upvotes: 0

Hesam
Hesam

Reputation: 53600

When you are using android:layout_weight="1" then wither of android:layout_width or android:layout_height should be equal to 0dp. In your case second linear layout should be android:layout_height="0dp"

Upvotes: 0

Related Questions