android 如何在网格布局的列之间显示垂直线

How to show a vertical line between columns of a grid layout in android

我正在制作原生 android 应用程序,我想在 网格布局 [=16] 中的两列 之间画一条 垂直线=],我有什么办法可以做到这一点吗?? 在下面的屏幕截图中,您可以看到单元格之间和列之间的线条。基本上,我只想用我自己的自定义样式显示网格。 This is the link to see the screenshots, apparently stack wont let me post a pic

您可以像这样添加垂直线 -

<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#000000" />

您可以根据需要设置高度,并且可以根据需要为上面的 View 添加边距

在您的网格布局中添加 verticalSpacing 并将 GridView 背景设置为您想要的线条颜色。

<GridView
        android:id="@+id/grid_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#DADADA"
        android:verticalSpacing="1dp"
        android:numColumns="2" />

如果您并排使用两个 LinearLayouts,您可以轻松使用框架分隔功能:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:divider="?android:listDivider"
    android:dividerPadding="2.5dp"
    android:orientation="horizontal"
    android:showDividers="middle"
    android:weightSum="2" > ... </LinearLayout>

另请参阅:http://developer.android.com/reference/android/widget/LinearLayout.html