安卓分线器

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

和两个朋友一起学习android,现在我们只关注UI部分。一个朋友给我们的任务是创建一个带有虚线分隔符的显示。我们想把它添加到Adapter文件中,这样它就可以作为回收器视图的一部分加载到我们的片段中,但是想不通怎么做。

下面是虚线可绘制的布局,在这里,虚线可绘制会被传递进来。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:id="@+id/dashes"
        android:background="@drawable/dashes_line"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>
android kotlin android-recyclerview rx-kotlin data-class
1个回答
0
投票

这是一个可以为RecyclerView设置分界线的方法。

recyclerView.addItemDecoration(DividerItemDecoration(context, VERTICAL).apply {
           setDrawable(getDrawable(context, R.drawable.separator))
    })

你可以根据自己的需要来改变可画性。

更新:添加可绘制分隔符.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line">
  <size android:height="3dp"/>
  <stroke
      android:color="#000000"
      android:dashWidth="10px"
      android:dashGap="10px"
      android:width="1dp"/>
</shape>

0
投票

你可以尝试替换Xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:id="@+id/text"
        android:background="@drawable/dashes_line"
        android:layout_width="match_parent"
        android:layout_height="wrap_parent"
        android:text="test"/>

    <ImageView
        android:id="@+id/dashes"
        android:background="@drawable/dashes_line"
        android:layout_width="match_parent"
        android:layout_height="1dp"/>
</LinearLayout>
© www.soinside.com 2019 - 2024. All rights reserved.