【问题标题】:How to show a vertical line between columns of a grid layout in android如何在android中的网格布局的列之间显示一条垂直线
【发布时间】:2016-06-16 13:18:35
【问题描述】:

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

【问题讨论】:

  • 检查this answer
  • 转到下面的链接你可能会找到你的解决方案stackoverflow.com/questions/12109126/…
  • 很多好的解决方案。如果我们用 1px ppl 而不是 1dp,你怎么看。在高规格的设备上,这条线看起来更漂亮更薄。这行得通吗?

标签: java android xml android-gridlayout


【解决方案1】:

在您的网格布局中添加 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" />

【讨论】:

    【解决方案2】:

    你可以像这样添加一条垂直线 -

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

    您可以根据需要设置高度,如果需要可以在上面的视图中添加边距

    【讨论】:

    • 我通常使用这个解决方案。但是,我不喜欢它有一个原因。这条线很粗,看起来不太好。我们如何做比 1 dp 更细的线。
    • 我正在使用网格视图布局
    • 即使您使用网格布局。你可以把它和这个建议的视图一起放在一个框架布局中。
    • @hasan83 ,您必须拥有用于网格项目的 XML 布局。只需在此处使用此代码,您就会得到一条垂直线。
    【解决方案3】:

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

    <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

    【讨论】:

      猜你喜欢
      • 2019-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-08
      • 2013-11-09
      相关资源
      最近更新 更多