无论我做什么,DividerItemDecoration都不会起作用

问题描述 投票:0回答:1

这是设置装饰的代码: -

recyclerView.addItemDecoration(new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.HORIZONTAL));

这是xml: -

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <size android:height="1dp" />
    <solid android:color="@android:color/black" />
</shape>

我尝试使用DividerItemDecoration.setDrawable(Drawable drawable)设置drawable并在我的主题中设置android:listDivider项目指向xml。

我也尝试将宽度设置为1dp。绝对没有用。

任何帮助表示赞赏,谢谢。

java android android-recyclerview recyclerview-layout
1个回答
1
投票

如果您的RecyclerView的方向是默认(垂直),那么您应该使用DividerItemDecoration.VERTICAL。

我刚刚尝试使用默认的DividerItemDecoration和你的xml资源创建一个RecyclerView,一切正常

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.