有没有可能的方法来制作这个自定义列表?

时间:2017-04-06 11:04:09

标签: android custom-lists

有没有可能的方法来执行android自定义列表视图,如下图所示? 自定义适配器应具有另一个列表视图,如下所示。enter image description here

提前致谢。

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

正如我所看到的,上图中的行数大小不一样。如果您的计划是以恐怖的方式构建列表项,则可以自己创建它,但也许这将是一项相对较大的任务(“重新发明轮子”,如果您知道我的意思)。在这里,您可以找到有关在ListViewTableLayout之间选择时应考虑的内容的SO主题,这可能是另一种解决方案:

ListView or TableLayout?

以我的拙见:因为我们在您的图片上看到的是一张桌子而 一个列表,应该使用TableLayout。

如果您也有意见,这里是TableLayout的官方教程指南......;)

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