2016-12-20 4 views
0

Я новичок в студии android. в настоящее время я сделать ListView, я хочу сделать макет, как изображения:Как сделать 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 косяк делать RowSpan, поэтому оно не работать ,

есть ли простой способ сделать это?

+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

Смежные вопросы