Javacadabra
Javacadabra

Reputation: 5758

Integrating a toolbar for application

I'm trying to integrate a bottom tool bar into my application. The bar will be used in a number of different activities so I am using the following line in my XML to include it with each layout:

<include
    android:layout_height="0dip"
    layout="@layout/test2" />

The output for test2.xml is as follows:

enter image description here

When I include it in my main activity the output looks like this:

enter image description here

I would like to have it so that the bar appears as close to the bottom as possible..I have no idea how to do this. Any suggestions would be much appreciated!

My activity_main.xml file looks like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="center|center_vertical"
android:orientation="vertical"
android:textAlignment="center"
android:weightSum="1" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="130dp"
    android:layout_weight="1"
    android:orientation="vertical"
    android:weightSum="1" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="@string/homeTitle"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <Button
        android:id="@+id/orderBtn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_margin="10dp"
        android:text="@string/orderbtn" />

    <Button
        android:id="@+id/viewBtn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:text="@string/viewbtn" />

    <Button
        android:id="@+id/feedbackBtn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:text="@string/feedbackbtn" />

    <Button
        android:id="@+id/payBtn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_margin="10dp"
        android:text="@string/paybtn" />

    <include
    android:layout_height="0dip"
    layout="@layout/test2" />


</LinearLayout>

Upvotes: 0

Views: 240

Answers (2)

Yauraw Gadav
Yauraw Gadav

Reputation: 1746

Wrap your code in a Relative Layout

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true">

     <include
         android:layout_height="0dip"
         layout="@layout/test2" />

</LinearLayout>

Upvotes: 1

Waza_Be
Waza_Be

Reputation: 39538

The layout at the top of the BottomBar should have these attributes:

<Linearlayout
    ....
    android:layout_height="0dip"
    android:layout_weight="1"
     />

While your bottom bar should have

<Linearlayout
    ....
android:layout_height="wrap_content"
     />

BE CAREFULL:

This is not related to your question, but such bottom bars belong to the iPhone.

The Home button should in fact looks like a up button: http://developer.android.com/design/patterns/navigation.html

And the three other parts should belong to the ActionBar: http://developer.android.com/design/patterns/actionbar.html

Upvotes: 0

Related Questions