gpt4 book ai didi

android - 带有自定义分隔线的 GridLayoutManager

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:31:54 25 4
gpt4 key购买 nike

我正在尝试使用 GridLayoutManagerRecyclerView 中添加自定义分隔线但没有成功,我已经搜索了很多并查看了下面提到的答案但它没有帮助我

link 1
link 2
link 3

我想在 RecyclerView 的每个项目之间放置黑线,如下所示。

enter image description here

我在每一行之间都有水平线,但无法找到如何在列之间也获得这些线。

chintan soni's答案非常有效,但它仅在一种情况下产生问题,当我有 5 个 View 时,它也显示其他 3 个项目的分隔线,如下所示:

enter image description here

最佳答案

检查一下:https://bignerdranch.github.io/simple-item-decoration/

将此添加到您的应用级别 gradle 和同步:

compile 'com.bignerdranch.android:simple-item-decoration:1.0.0'

然后,应用如下代码:

    Drawable horizontalDivider = ContextCompat.getDrawable(this, R.drawable.line_divider);
Drawable verticalDivider = ContextCompat.getDrawable(this, R.drawable.line_divider);
recyclerView.addItemDecoration(new GridDividerItemDecoration(horizontalDivider, verticalDivider, 4));

我的 line_divider.xml 如下:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<size
android:width="1dp"
android:height="1dp" />

<solid android:color="@android:color/black" />

</shape>

这只是我的快速回答。但我想这应该有用..

输出: enter image description here

关于android - 带有自定义分隔线的 GridLayoutManager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39490124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com