2016-12-20 29 views
0

我是android studio中的新成員。 目前我做的ListView,我要進行佈局像這樣的畫面:如何使用tablerow製作列表視圖

enter image description here

現在這是我的代碼

<TableLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true"> 

    <TableRow 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:weightSum="3"> 

     <TableLayout 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1.5"> 

      <TableRow 

       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="15dp" 
       android:layout_marginLeft="10dp" 
       > 


       <TextView 
        android:layout_width="0dp" 
        android:layout_weight="1" 
        android:layout_height="wrap_content" 
        android:textAppearance="?android:attr/textAppearanceMedium" 
        android:text="Type" 
        android:textSize="18dp" 
        android:fontFamily="sans-serif" 
        android:textColor="@color/black" 
        android:id="@+id/tvTipeRequest" 
        android:width="130dp" /> 
      </TableRow> 

      <TableRow 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="10dp" 
       android:layout_marginTop="10dp" 
       > 

       <TextView 
        android:layout_width="0dp" 
        android:layout_weight="1" 
        android:layout_height="wrap_content" 
        android:textAppearance="?android:attr/textAppearanceMedium" 
        android:text="Date" 
        android:fontFamily="sans-serif" 
        android:id="@+id/tvTanggalRequest" 
        android:textSize="15dp" 
        android:width="130dp" /> 

      </TableRow> 


     </TableLayout> 

     <TextView 
      android:layout_width="1dp" 
      android:layout_weight="1" 
      android:layout_height="50dp" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:textColor="@color/black" 
      android:text="Status" 
      android:textSize="15dp" 
      android:gravity="end" 
      android:paddingTop="10dp" 
      android:fontFamily="sans-serif" 
      android:layout_marginTop="15dp" 
      android:id="@+id/tvStatus" 
      android:layout_column="38" /> 

    </TableRow> 

</TableLayout> 

我意識到tablerow的不能做的行跨度,所以它沒有工作了。

有沒有簡單的方法來做到這一點?

+1

就這麼簡單,你可以用'LinearLayout'與水平父佈局和孩子與垂直方向佈局。 – Piyush

+0

如果你不介意,你能寫出示例代碼嗎?我不是很瞭解這個方向。 – Borom1r

回答

1

使用該層次結構:

<LinearLayout 
    android:layout_width="match_parent" 
    android:orientation="horizontal" 
    android:weightSum="1" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_weight="0.2" 
     android:orientation="vertical" 
     android:layout_height="wrap_content"> 

     <!--ImageView here--> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_weight="0.8" 
     android:orientation="vertical" 
     android:layout_height="wrap_content"> 

     <!--All textViews here--> 
    </LinearLayout> 

</LinearLayout> 
1

你可以有一個相對單一佈局視圖容器。那樣會更有效率。

Read.

佈局:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <ImageView 
     android:id="@+id/image_view" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_alignParentLeft="true" 
     android:layout_marginLeft="16dp" 
     android:layout_marginRight="16dp" 
     android:layout_marginTop="8dp" 
     android:src="@drawable/circle" /> 

    <TextView 
     android:id="@+id/text_view_1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/image_view" 
     android:text="text_1" 
     android:textColor="@android:color/black" /> 

    <TextView 
     android:id="@+id/text_view_2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/text_view_1" 
     android:layout_toRightOf="@+id/image_view" 
     android:text="text_2" 
     android:textColor="@android:color/black" /> 

    <TextView 
     android:id="@+id/text_view_3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/text_view_2" 
     android:layout_toRightOf="@+id/image_view" 
     android:text="text_3" 
     android:textColor="@android:color/black" /> 

    <TextView 
     android:id="@+id/text_view_4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/text_view_3" 
     android:layout_toRightOf="@+id/image_view" 
     android:text="text_4" 
     android:textColor="@android:color/black" /> 
</RelativeLayout> 

輸出:

enter image description here

相關問題