2013-09-21 47 views
1

我想设计是这样的:左浮动的TextView和TableLayout

[TableLayout 1 Title] TextView1

[TableLayout 1]

[TableLayout 2 Title] TextView2

[TableLayout 2]

就像在CSS,我们只需使用:浮子:用设置t离开他在100%的宽度,一切都很好。

,所以这是我的布局XML代码:

<RelativeLayout 
    android:layout_width="match_parent" 
    android:background="#e9e9e9" 
    android:layout_height="match_parent" > 


    <TextView 
     android:id="@+id/TextView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:text="Visitors per Category" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#324A61" 
     android:layout_marginLeft="7dp" 
     android:layout_marginTop="25dp" 
     android:textStyle="bold" /> 

    <TableLayout 
     android:id="@+id/TableLayout1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_marginTop="50dp" 
     android:layout_marginBottom="10dp" 
     android:layout_marginLeft="7dp" 
     android:layout_marginRight="7dp" 
     android:stretchColumns="2" 
     android:background="@drawable/shape" > 

     <TableRow 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="15dp" > 

      // Some EditText etc... 

     </TableRow> 

     // Separator border 
     <View 
      android:id="@+id/firstDivider" 
      android:layout_height="2dp" 
      android:layout_width="fill_parent" 
      android:background="#666" /> 

     <TableRow 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="15dp" > 

      // Some textviews etc... 

     </TableRow> 
    </TableLayout> 

    <TextView 
     android:id="@+id/EditText2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_marginBottom="60dp" 
     android:text="Scans per Gate" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#324A61" 
     android:textStyle="bold" /> 

    <TableLayout 
     android:id="@+id/TableLayout2" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_marginTop="205dp" 
     android:layout_marginBottom="10dp" 
     android:layout_marginLeft="7dp" 
     android:layout_marginRight="7dp" 
     android:stretchColumns="2" 
     android:background="@drawable/shape" > 

     <TableRow 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="15dp" > 

      // some textviews etc... 

     </TableRow> 

     <View 
      android:id="@+id/firstDivider" 
      android:layout_width="fill_parent" 
      android:layout_height="2dp" 
      android:background="#666" /> 

     <TableRow 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="15dp" > 

      // Some textViews 
     </TableRow> 
    </TableLayout> 

</RelativeLayout> 

一切看起来正常,我的代码,但图形我有类似:

TextView2

TextView1

TableLayout2TableLayout1

你对此有什么想法吗?

谢谢。

回答

3

尝试使用线性布局,垂直方向

<LinearLayout 
    android:layout_width="match_parent" 
    android:background="#e9e9e9" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 


    <TextView 
     android:id="@+id/TextView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:text="Visitors per Category" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#324A61" 
     android:layout_marginLeft="7dp" 
     android:layout_marginTop="25dp" 
     android:textStyle="bold" /> 

    <TableLayout 
     android:id="@+id/TableLayout1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="left" 
     android:layout_marginTop="50dp" 
     android:layout_marginBottom="10dp" 
     android:layout_marginLeft="7dp" 
     android:layout_marginRight="7dp" 
     android:stretchColumns="2" 
     android:background="@drawable/shape" > 

     <TableRow 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="15dp" > 

      // Some EditText etc... 

     </TableRow> 

     // Separator border 
     <View 
      android:id="@+id/firstDivider" 
      android:layout_height="2dp" 
      android:layout_width="fill_parent" 
      android:background="#666" /> 

     <TableRow 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="15dp" > 

      // Some textviews etc... 

     </TableRow> 
    </TableLayout> 

    <TextView 
     android:id="@+id/EditText2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="left" 
     android:layout_marginBottom="60dp" 
     android:text="Scans per Gate" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#324A61" 
     android:textStyle="bold" /> 

    <TableLayout 
     android:id="@+id/TableLayout2" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="left" 

     android:layout_marginBottom="10dp" 
     android:layout_marginLeft="7dp" 
     android:layout_marginRight="7dp" 
     android:stretchColumns="2" 
     android:background="@drawable/shape" > 

     <TableRow 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="15dp" > 



     </TableRow> 

     <View 
      android:id="@+id/firstDivider" 
      android:layout_width="fill_parent" 
      android:layout_height="2dp" 
      android:background="#666" /> 

     <TableRow 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="15dp" > 


     </TableRow> 
    </TableLayout> 

</LinearLayout> 

这应该工作

+0

哇!它完美的作品!这绝对是一个很好的答案! 但请您可以告诉我为什么使用线性布局?谢谢。 – Copernic

+0

如果它工作,请[accept_the_answer](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)。LinearLayout用于想要线性对齐您的子视图通过给定方向为水平或垂直。有关更多信息,请参阅[布局](http://developer.android.com/guide/topics/ui/declaring-layout.html) – Manishika

+0

谢谢您的回答。 – Copernic