【问题标题】:Issue with Relative/Table Layout相对/表格布局问题
【发布时间】:2015-05-09 14:49:37
【问题描述】:

我希望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>

【问题讨论】:

    标签: android layout android-relativelayout tablelayout


    【解决方案1】:

    嗯,你可以用RelativeLayout 来做,我不明白你为什么说你做不到。但是如果你想用TableLayout,那么你需要两个TableRow,一个用TextViews,另一个用EditText。因此,TableLayout 的子代将是 TableRows。

    但是,我建议您使用RelativeLayout,它更便宜,因为它不必计算东西并且它在堆栈中只有一层。

    你可以先定义你的三个EditText,然后是每个EditText上方的三个TextView,如果你想让它们居中,那么你可以左右对齐EditTexts。 希望对您有所帮助,让我知道您的想法

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多