2017-04-06 142 views
-3

是否有任何可能的方式來做像下面的圖像的Android自定義列表視圖? 自定義適配器應該有另一個listview如下。 enter image description here是否有任何可能的方法來製作這個自定義列表?

在此先感謝。

+0

要麼是另一個小部件,或者通過使用有幾個定製單元模擬表'列'和可能行。 –

+0

您可以使用TableLayout而不是自定義的listview。 –

回答

0

activity_main.xml中

<LinearLayout 
    android:id = "@+id/relativeLayout1" 
    android:layout_width = "fill_parent" 
    android:layout_height = "wrap_content" > 

    <TextView 
     android:layout_width = "0dp" 
     android:layout_height = "wrap_content" 
     android:layout_weight = "2" 
     android:gravity = "center" 
     android:padding = "5dp" 
     android:text = "Firt column title" 
     android:textColor = "#ffffff"/ > 

    <TextView 
     android:layout_width = "0dp" 
     android:layout_height = "wrap_content" 
     android:layout_weight = "1.5" 
     android:gravity = "center" 
     android:padding = "5dp" 
     android:text = "Second column title" 
     android:textColor = "#ffffff" /> 

    <TextView 
     android:layout_width = "0dp" 
     android:layout_height = "wrap_content" 
     android:layout_weight = "1" 
     android:gravity = "center" 
     android:padding = "5dp" 
     android:text = "third column title" 
     android:textColor = "#ffffff" /> 
</LinearLayout> 

<ListView 
    android:id = "@+id/listview" 
    android:layout_width = "match_parent" 
    android:layout_height = "wrap_content" 
    android:divider = "@null"/> 

cell_shape.xml

<layer-list xmlns:android = "http://schemas.android.com/apk/res/android"> 

<item 
    android:left = "-2dp" 
    android:top = "-2dp"> 
    <shape android:shape = "rectangle" > 
     <solid android:color = "@android:color/transparent" /> 

     <stroke 
      android:width = "1dp" 
      android:color = "@color/colorCell" /> 
    </shape> 
</item> 

listview_row.xml

<LinearLayout 
    android:id = "@+id/relativeLayout1" 
    android:layout_width = "fill_parent" 
    android:layout_height = "wrap_content" 
    android:background = "@color/colorCell" > 

    <TextView  
     android:id = "@+id/sNo"  
     android:layout_width = "0dp" 
     android:layout_height = "match_parent" 
     android:layout_weight = "1" 
     android:background = "@drawable/cell_shape" 
     android:ellipsize = "end" 
     android:padding = "5dp" 
     android:text = "categorie" 
     android:singleLine = "true" /> 

<ListView 
    android:id = "@+id/listview_first section list" 
    android:layout_width = "match_parent" 
    android:layout_height = "wrap_content" 
    android:divider = "@null"/> 
<ListView 
    android:id = "@+id/listview_number_section_list" 
    android:layout_width = "match_parent" 
    android:layout_height = "wrap_content" 
    android:divider = "@null"/> 


</LinearLayout> 
+0

我的對象是List中的每個類別。那麼爲什麼我需要使用兩個listview和textview?你能否請編輯答案 – CarinaMj

+0

看看這個例子希望能對你有所幫助 –

0

正如我所看到的,由上述中的行是大小不一樣。如果您的計劃是要建立列表項目,但可能自己創建它,但也許這將是一個相對較大的任務(「重新發明方向盤」,如果您知道我的意思)。在這裏,你可以找到當你有ListViewTableLayout之間做出選擇,你應該考慮什麼,這可能是另一種解決方案SO話題:

ListView or TableLayout?

在我的愚見:因爲我們可以在圖像上看到是表和不是一個表,它應該用TableLayout來做。

如果這是你的意見也是如此,這裏是官方教程指南TableLayout ...;)

https://developer.android.com/guide/topics/ui/layout/grid.html

相關問題