0

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>
double-beep
  • 5,031
  • 17
  • 33
  • 41
Pelanes
  • 3,451
  • 1
  • 34
  • 32

2 Answers2

2

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>
waqaslam
  • 67,549
  • 16
  • 165
  • 178
  • It doesn't work, it crashes :( 04-21 17:05:06.363: E/AndroidRuntime(20964): java.lang.RuntimeException: Unable to start activity ComponentInfo{es.hsk.ap/es.hsk.ap.juega.Trazos}: java.lang.ClassCastException: android.gesture.GestureOverlayView – Pelanes Apr 21 '12 at 17:06
  • then remove `android.gesture.GestureOverlayView` from your layout, clean the project and then run it. Actually I didnt add **GestureOverlayView** to the layout myself, it was already mentioned in your layout. If its crashing then how were you able to run it? – waqaslam Apr 21 '12 at 17:19
  • It crashes when I change LineaLayout to RelativeLayout as you said at first. I can't remove this view, I need it. And the problem isn't it, it happens if you use other layout in the middle, like a imageview – Pelanes Apr 23 '12 at 12:06
  • dont simply replace the word LinearLayout with RelativeLayout... just copy the entire xml in my answer and replace it to the one you have... – waqaslam Apr 23 '12 at 12:10
0

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.

Austyn Mahoney
  • 11,398
  • 8
  • 64
  • 85
  • I have tried a LinearLayout instead TableRow, but same problem, the object view on it, use all the screen size. I want to use all the avaible screen, but with these two buttons visible at bottom of layout. Thanks! – Pelanes Apr 21 '12 at 17:11