GridLayout边框线/可见分隔符?

时间:2017-04-02 15:48:09

标签: android gridview

我对android比较新,我想知道如何在图像周围放置一个可见的分隔符/边框。

Example grid menu with border/dividers

2 个答案:

答案 0 :(得分:0)

在项目的布局中,您可以放置​​一个高度为1dp或宽度为1dp的视图,并用一些颜色填充它。这是包含文本和底部分隔符的列表的项目。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/colorPrimary"/>
</FrameLayout>

答案 1 :(得分:0)

您可以尝试使用所需边框颜色的值为android:background添加ImageView属性。然后使用所需边框宽度的值向android:padding添加ImageView属性。这不是最优雅的解决方案,但它是可以理解的,并且对于新的开发人员来说会做得很好。例如:

<ImageView
    android:id="@+id/list_item_icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/android_image"
    android:background="color/list_item_icon_border_color"
    android:padding="1dp"
    />

执行此操作的正确方法可能是使用自定义XML drawable。您可以使用自定义XML drawable检查Google是否为ImageView创建边框。然而,与上面提到的方法相比,它是一种更复杂的方式,它可能是一种从XML定义的自定义drawable开始的绝佳方式。迟早你不得不理解它,别无他法。对于圆形边框检查这篇文章 - 使用自定义XML drawable的漂亮和清晰的解释: Create circular border around ImageView

相关问题