【发布时间】:2017-09-17 22:56:31
【问题描述】:
在我的应用程序中,我正在使用一个包含许多项目的回收站视图,我想在项目之间显示一个点分隔符(分隔线),但它不起作用。我已经尝试创建一个可绘制的形状,但是在将可绘制对象添加到 DividerItemDecoration 之后,回收站视图项之间没有显示空间或线条。 我也尝试过创建自定义 DividerItemDecoration 类,但对我没有任何作用。 注意: 目前我的可绘制形状设置为矩形,我也尝试过线条。 如何实现。任何帮助将不胜感激。 这是我的代码。
可绘制:(customdrawableshape.xml)
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="3dp"
android:height="2dp"
android:color="#000000"
android:dashGap="10dp"
android:dashWidth="5dp" />
</shape>
回收站视图项的自定义行
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginBottom="2dp">
<TextView
android:id="@+id/tv_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
以及我将项目装饰设置为 recyclerview 的代码部分
DividerItemDecoration dividerItemDecoration;
recyclerview.setLayoutManager(linearlayoutmanager);
dividerItemDecoration = new DividerItemDecoration(recyclerview.getContext(),
linearlayoutmanager.getOrientation());
dividerItemDecoration.setDrawable(ContextCompat.getDrawable(context, R.drawable.customdrawableshape));
recyclerview.addItemDecoration(dividerItemDecoration);
【问题讨论】:
-
recyclerview 后面那个多余的点
.是不是错字? -
@BlackHatSamurai 哦,是的,这是一个打字错误
-
你用尺码试了吗?见:stackoverflow.com/a/5501449/1837367
标签: android android-recyclerview