Mike
Mike

Reputation: 1312

TextView in the bottom of the LinearLayout

I'm trying to put the textview at the bottom of the layout, but it doesn't work. Please help me to get the textview to the bottom of the screen. I tried gridlayout but I don't really understand the way to use it.

Thank you

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:background="@drawable/background1" >

    <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

        <TextView
                android:id="@+id/textView1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="30dp"
                android:gravity="center"
                android:text="Tour Main Menu"
                android:textSize="@dimen/font_large" />   
    </LinearLayout> 

    <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

        <TextView
                android:id="@+id/tour_info"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="30dp"
                android:gravity="center"
                android:text="There are 47 Passengers"
                android:textSize="@dimen/font_medium" />   

    </LinearLayout> 

    <TableLayout  
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="5dp"
            android:shrinkColumns="*"
            android:paddingRight="5dp"
            android:orientation="vertical" >
        <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >


            <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >"

                <ImageButton
                        android:id="@+id/passenger_list"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginRight="10dp"
                        android:layout_marginLeft="10dp"
                        android:gravity="center_horizontal|center_vertical"
                        android:background="@drawable/icon"
                        android:contentDescription="@string/pass_list"  />    

                <TextView
                        android:id="@+id/passenger_list_text"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:text="@string/pass_list"
                        android:textSize="@dimen/font_medium" />

            </LinearLayout>
            <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >

                <ImageButton
                        android:id="@+id/arrivals"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center_horizontal|center_vertical"
                        android:background="@drawable/icon"
                        android:layout_marginRight="10dp"
                        android:layout_marginLeft="10dp"
                        android:padding="44dp"
                        android:contentDescription="@string/arrivals" />

                <TextView
                        android:id="@+id/arrivals_text"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:text="@string/arrivals"
                        android:textSize="@dimen/font_medium" />

            </LinearLayout>
            <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >

                <ImageButton
                        android:id="@+id/departures"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginRight="10dp"
                        android:layout_marginLeft="10dp"
                        android:background="@drawable/icon"
                        android:contentDescription="@string/departures" />

                <TextView
                        android:id="@+id/departures_text"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:text="@string/departures"
                        android:textSize="@dimen/font_medium" />    .

            </LinearLayout>

            <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >
                <ImageButton
                        android:id="@+id/master_rooming"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginRight="10dp"
                        android:layout_marginLeft="10dp"
                        android:background="@drawable/icon"
                        android:contentDescription="@string/rooming" />

                <TextView
                        android:id="@+id/master_rooming_text"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:text="@string/rooming"
                        android:textSize="@dimen/font_medium" />        
            </LinearLayout>
        </TableRow>

        <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingTop="50dp" >


            <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >"

                <ImageButton
                        android:id="@+id/itinerary"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginRight="10dp"
                        android:layout_marginLeft="10dp"
                        android:background="@drawable/icon"
                        android:contentDescription="@string/itinerary" />   

                <TextView
                        android:id="@+id/itinerary_text"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:text="@string/itinerary"
                        android:textSize="@dimen/font_medium" />    

            </LinearLayout>
            <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >

                <ImageButton
                        android:id="@+id/qa"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginRight="10dp"
                        android:layout_marginLeft="10dp"
                        android:background="@drawable/icon"
                        android:contentDescription="QA" />  

                <TextView
                        android:id="@+id/qa_text"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:text="QA"
                        android:textSize="@dimen/font_medium" />

            </LinearLayout>
            <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >
                <ImageButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginRight="10dp"
                        android:layout_marginLeft="10dp"
                        android:background="@drawable/icon"
                        android:contentDescription="QA" />  

                <TextView
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:text="Text Here"
                        android:textSize="@dimen/font_medium" />

            </LinearLayout>

            <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >
                <ImageButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginRight="10dp"
                        android:layout_marginLeft="10dp"
                        android:background="@drawable/icon"
                        android:contentDescription="QA" />  

                <TextView
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:text="Text Here"
                        android:textSize="@dimen/font_medium" />

            </LinearLayout>
        </TableRow> 
    </TableLayout>


    <!-- Time Stamp at the bottom of the screen -->

    <TextView
        android:id="@+id/timeStamp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom|center"
        android:text=""
        android:textSize="@dimen/font_medium" />

</LinearLayout>

Upvotes: 1

Views: 3401

Answers (1)

Streets Of Boston
Streets Of Boston

Reputation: 12596

Try this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/background1" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:layout_weight="0"
        >
    ...   
    </LinearLayout> 

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:layout_weight="0"
        >
    ...   
    </LinearLayout> 

    <TableLayout  
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:paddingLeft="5dp"
        android:shrinkColumns="*"
        android:paddingRight="5dp"
        android:orientation="vertical" >
    ...   
    </TableLayout>


    <!-- Spacer: stretches causing the TextView below to move to the bottom of the screen -->
    <View 
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
    />

    <!-- Time Stamp at the bottom of the screen -->

    <TextView
        android:id="@+id/timeStamp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:text=""
        android:textSize="@dimen/font_medium" />

</LinearLayout>

The idea is to attach android:layout_weight to each child of LinearLayout. All of them have a weight of 0, meaning, they do not stretch to fill available space. Except one, the View. It has a weight of 1, meaning it will receive all available space and stretch, effectively moving the TextView below to the bottom.

Upvotes: 4

Related Questions