2011-02-22 104 views
1

我希望TextView始終位於所有設備屏幕上每個EditText的頂部。首先,我試圖用RelativeLayout做一些事情,但它不起作用。現在,我正在嘗試TableLayout。我希望你的意見爲這個使用最好的佈局!相對/表格佈局問題

這裏是我的代碼:

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:stretchColumns="2" 
    android:background="@drawable/back" > 

    <TextView android:id="@+id/mathimatika" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Mathimatika Kateuthinsis" 
      android:textColor="#09074c" 
      android:textSize="14px" 
      android:gravity="center" /> 

    <TableRow> 
     <TextView 
       android:layout_column="1" 
       android:text="Profwrika a" 
       android:padding="13dip" 
       android:textColor="#09074c" 
       android:textSize="10px"/> 
     <TextView 
      android:text="Profwrika b" 
      android:gravity="center" 
      android:textColor="#09074c" 
      android:textSize="10px" /> 

     <TextView 
      android:text="grapta" 
      android:gravity="right" 
      android:padding="13dip" 
      android:textColor="#09074c" 
      android:textSize="10px" /> 
    </TableRow> 
    <RelativeLayout> 
      <EditText 
       android:id="@+id/input11" 
       android:layout_width="60px" 
       android:layout_height="wrap_content" 
       android:textSize="18sp" 
       android:numeric="decimal|signed" 
       android:layout_below="@id/vathmos1" 
       android:layout_marginLeft="13dip" /> 

     <EditText 
       android:id="@+id/input21" 
       android:layout_width="60px" 
       android:layout_height="wrap_content" 
       android:textSize="18sp" 
       android:numeric="decimal|signed"  
       android:layout_toRightOf="@id/input11" 
       android:layout_below="@id/vathmos1" 
       android:layout_marginLeft="25px" /> 

     <EditText 
       android:id="@+id/input31" 
       android:layout_width="60px" 
       android:layout_height="wrap_content" 
       android:textSize="18sp" 
       android:numeric="decimal|signed" 
       android:layout_toRightOf="@id/input21" 
       android:layout_below="@id/vathmos1" 
       android:layout_marginLeft="25px" /> 

    </RelativeLayout> 
</TableLayout> 

回答

0

好了,你可以用RelativeLayout做到這一點,我不明白爲什麼你說你不能做到這一點。但是如果你想用TableLayout,那麼你需要有兩個TableRow,一個用TextViews,另一個用EditText。因此,TableLayout的孩子將是TableRow

但是,我會建議您使用RelativeLayout,它更便宜,因爲它不必計算堆棧中的東西和唯一的一個層次。

你可以定義你的三個EditText第一,那麼三個TextView S中的每個EditText以上,而如果你想讓他們爲中心,那麼你既可以在左側和右側對齊到EditText秒。 我希望這可以幫助,讓我知道你在想什麼