Question

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>
Was it helpful?

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>

OTHER TIPS

EDIT: Your root element should be a TableLayout if you want to use the features contained in that View. You currently have it as a LinearLayout.

I don't see anything mentioning how non TableRow Views are vertically placed in the documentation.

From my experience, a TableLayout will always place things directly below the last row.

Have tried using a RelativeLayout, or LinearLayout to accomplish what you need? It is much more flexible than a TableLayout.

You could also close your TableLayout and place a LinearLayout below it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top