Search code examples
androidandroid-layoutandroid-xmlgravityandroid-layout-weight

Place View at bottom of a screen/layout using a TableLayout


I am trying to place a TableRow with two Buttons at the bottom of the screen, under other view elements in the layout, but if I put there, the TableRow dissappear out of the screen. I I put at top or in the middle, no problem.

I was trying a lot of layout_gravity, gravity and weight combinations, but I can't get it.

screenshot of the layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:gravity="center_horizontal" 
    android:text="@string/traza" 
    android:layout_margin="10sp"/>

    <TableRow
        android:id="@+id/tableRow8"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="3sp"
        android:gravity="center"
        android:weightSum="2" >

        <Button
            android:id="@+id/reiniciar"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_margin="5sp"
            android:background="@drawable/bordebutton"
            android:text="@string/reiniciar" />

        <Button
            android:id="@+id/comprobar"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_margin="5sp"
            android:background="@drawable/bordebutton"
            android:text="@string/comprobar" />

    </TableRow>

<android.gesture.GestureOverlayView
    android:id="@+id/gestures"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:fadeEnabled="true"
    android:fadeOffset="3000"
    android:gestureStrokeType="multiple"
    android:eventsInterceptionEnabled="true"
    android:orientation="vertical"/>
</LinearLayout>

Solution

  • You need to use RelativeLayout to achieve this.

    There you go:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10sp"
            android:gravity="center_horizontal"
            android:text="@string/traza"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    
        <TableRow
            android:id="@+id/tableRow8"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="3sp"
            android:gravity="center"
            android:weightSum="2"
            android:layout_alignParentBottom="true" >
    
            <Button
                android:id="@+id/reiniciar"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5sp"
                android:layout_weight="1"
                android:background="@drawable/bordebutton"
                android:text="@string/reiniciar" />
    
            <Button
                android:id="@+id/comprobar"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5sp"
                android:layout_weight="1"
                android:background="@drawable/bordebutton"
                android:text="@string/comprobar" />
        </TableRow>
    
        <android.gesture.GestureOverlayView
            android:id="@+id/gestures"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:eventsInterceptionEnabled="true"
            android:fadeEnabled="true"
            android:fadeOffset="3000"
            android:gestureStrokeType="multiple"
            android:orientation="vertical" />
    
    </RelativeLayout>