2012-04-20 81 views
0

我想在屏幕的底部放置一個TableRow,在佈局的其他視圖元素下放置兩個按鈕,但是如果放到那裏,TableRow消失的屏幕。我把我放在頂部或中間,沒問題。使用TableLayout在屏幕底部的位置視圖

我正在嘗試很多layout_gravity,重力和重量組合,但我無法得到它。

在此先感謝。

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> 

回答

2

您需要使用RelativeLayout來實現此目的。

你去那裏:

<?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> 
+0

它不起作用,它崩潰:(04-21 17:05:06.363:E/AndroidRuntime(20964):java.lang.RuntimeException:無法啓動活動ComponentInfo {es.hsk.ap/es.hsk.ap .juega.Trazos}:java.lang.ClassCastException:android.gesture.GestureOverlayView – Pelanes 2012-04-21 17:06:28

+0

然後從您的佈局中刪除'android.gesture.GestureOverlayView',清理項目,然後運行它。實際上我沒有添加** GestureOverlayView **到佈局我自己,它已經在你的佈局中提到過,如果它崩潰,那麼你怎麼能夠運行它? – waqaslam 2012-04-21 17:19:48

+0

當我將LineaLayout更改爲RelativeLayout時,它會崩潰,因爲你剛開始時說過,我不能移除這個視圖,我需要它。問題不是這樣,它會發生,如果您在中間使用其他佈局,像imageview – Pelanes 2012-04-23 12:06:03

0

編輯: 你的根元素應該是一個,如果你想使用包含在View功能TableLayout。您目前將其作爲LinearLayout

我沒有看到任何提及非TableRow視圖如何垂直放置在documentation

根據我的經驗,TableLayout將始終將事物放置在最後一行的正下方。

已嘗試使用RelativeLayoutLinearLayout來完成您所需的功能嗎?它比TableLayout靈活得多。

您還可以關閉您的TableLayout並且在其下方放置一個LinearLayout

+0

我已經嘗試了的LinearLayout代替的TableRow,但同樣的問題,它的對象視圖,使用所有的屏幕尺寸。我想使用所有可用的屏幕,但是這兩個按鈕在佈局的底部可見。謝謝! – Pelanes 2012-04-21 17:11:26

相關問題