Use*_*ser 0 android android-recyclerview
在我的应用程序中,我使用包含许多项目的回收站视图,我想在项目之间显示一个无线分隔符(分隔线),但它不起作用.我已经尝试创建一个可绘制的形状,但是如果在dividerItemDecoration中添加drawable,则不会在回收器视图项之间显示空格或线.我也尝试过创建自定义的DividerItemDecoration类,但对我来说没什么用. 注意:目前在我的drawable形状设置为矩形我也试过线.如何实现.任何帮助将不胜感激.这是我的代码.
绘制对象:(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>
Run Code Online (Sandbox Code Playgroud)
回收站视图项的自定义行
<?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>
Run Code Online (Sandbox Code Playgroud)
以及我将项目装饰设置为recyclerview的代码部分
DividerItemDecoration dividerItemDecoration;
recyclerview.setLayoutManager(linearlayoutmanager);
dividerItemDecoration = new DividerItemDecoration(recyclerview.getContext(),
linearlayoutmanager.getOrientation());
dividerItemDecoration.setDrawable(ContextCompat.getDrawable(context, R.drawable.customdrawableshape));
recyclerview.addItemDecoration(dividerItemDecoration);
Run Code Online (Sandbox Code Playgroud)
你可以用DividerItemDecorationclass来添加行.
这是示例代码
recyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5660 次 |
| 最近记录: |