2015-03-19 87 views
1

這是我的TableLayout代碼:的Android TableLayout - 文本視圖和按鈕同一列內

<TableLayout 
 
    android:layout_width="1200dp" 
 
    android:layout_height="wrap_content" 
 
    android:layout_marginTop="40dp" 
 
    android:layout_marginLeft="40dp" > 
 
     
 
    <TableRow> 
 
     <TextView 
 
      \t android:text="ADDRESS" 
 
      android:background="@drawable/cell_shape" 
 
      android:textColor="@color/white" 
 
      android:layout_weight="1" 
 
      style="TableTitle" /> 
 

 
     <TextView 
 
      android:text="TENANCY" 
 
      android:background="@drawable/cell_shape" 
 
      android:textColor="@color/white" 
 
      android:layout_weight="1" 
 
      \t style="TableTitle" /> 
 
     
 
     <TextView 
 
      android:text="LOCATION" 
 
      android:background="@drawable/cell_shape" 
 
      android:textColor="@color/white" 
 
      android:layout_weight="5" 
 
      \t style="TableTitle" /> 
 
      
 
     <TextView 
 
      android:text="NAME" 
 
      android:background="@drawable/cell_shape" 
 
      android:textColor="@color/white" 
 
      android:layout_weight="1" 
 
      \t style="TableTitle" /> 
 
     
 
     <TextView 
 
      android:text="SELECTION" 
 
      android:background="@drawable/cell_shape" 
 
      android:textColor="@color/white" 
 
      android:layout_weight="1" 
 
\t \t \t style="TableTitle" /> 
 
     
 
    </TableRow>

然後我繪製/ cell_shape如下:

<?xml version="1.0" encoding="utf-8"?> 
 
<shape 
 
    xmlns:android="http://schemas.android.com/apk/res/android" 
 
    android:shape= "rectangle" 
 
    android:name="@+id/rec1" > 
 
    
 
     <solid android:color="#30383F" 
 
       android:padding="10dp" /> 
 
     <scale 
 
       android:scaleHeight="200" 
 
       android:scaleWidth="200" /> 
 
     
 
     <stroke 
 
       android:width="1dp" 
 
       android:color="#D9D9D6" /> 
 
     <padding 
 
       android:left="10dp" 
 
       android:top="10dp" 
 
       android:right="10dp" 
 
       android:bottom="10dp" /> 
 

 
</shape>

我可以設置表格,但是我的問題是我能夠在文本視圖右側的列中添加一個按鈕。這可能嗎?

例如,在第一列中,我希望它說「地址」,然後向右幾個像素,因爲那裏有一個按鈕,全部在同一列內。謝謝你的幫助 !

回答

3

可以包括相對或線性佈局,包括在每列

<TableRow> 
<Relativelayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
<TextView 
      android:text="ADDRESS" 
      android:background="@drawable/cell_shape" 
      android:textColor="@color/white" 
      android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
      style="TableTitle" /> 

<Button 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 


      android:id="@+id/addbtn" 
      android:clickable="false" 


      android:layout_alignParentRight="true"  
      /> 
</Relativelayout> 
+0

這個工作的按鈕和文本!感謝那。欣賞它:) – Will 2015-03-20 05:37:56

+0

我想你的答案,但我沒有足夠的代表,請記住我的問題? – Will 2015-03-20 05:38:26

+0

完成你:) – 2015-03-20 05:42:27