如何从recylerview中删除默认分隔符

时间:2022-05-22 22:41:46

I have added android-recyclerview in my app which is running fine. According to my layout i have to remove divider between cells. In list view this can easily be achieved by setting divider property to null like below in code but i am not able to find any such property in android-recyclerview. How can i achieve this in android-recyclerview.

我在我的app中添加了android-回收视图,运行良好。根据我的布局,我必须在细胞之间移除分割线。在列表视图中,可以通过在代码中将divider属性设置为null来实现这一点,但是我无法在android-recycle -视图中找到任何这样的属性。我如何在android-回收视图中实现这一点。

getListView().setDivider(null);
getListView().setDividerHeight(0);
     OR
android:divider="@null"
android:dividerHeight="0dp"

Recylerview xml below :

Recylerview xml下面:

<android.support.v7.widget.RecyclerView
                android:id="@+id/recycler_view_contact_list_frag"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="0.8"
                android:clickable="true"
                android:focusable="true"
                android:scrollbars="vertical" />

Adapter xml :

适配器xml:

<?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:background="@drawable/recyclerview_item_borders"
android:padding="10dp">

<LinearLayout
    android:id="@+id/section_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:visibility="gone"
    android:paddingBottom="30dp"
    >


<TextView
    android:id="@+id/textview_section_header"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    >
    <de.hdodenhof.circleimageview.CircleImageView   xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/circular_image_contact"
      android:layout_width="@dimen/auto_complete_circular_image_dimen"
        android:layout_height="@dimen/auto_complete_circular_image_dimen"
        app:civ_border_color="#FF000000"
        android:layout_weight="0.2"
        android:src="@mipmap/ic_default_contact"
        app:civ_border_width="0dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.8"
        android:orientation="vertical">

        <TextView
            android:id="@+id/textView_contact_name"
            android:layout_width="match_parent"
            android:layout_gravity="center_vertical"
            android:gravity="center_vertical"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:textColor="@color/textDarkColor"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true" />

        <TextView
            android:id="@+id/textView_contact_number"
            android:layout_width="match_parent"
            android:layout_gravity="center_vertical"
            android:gravity="center_vertical"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:textColor="@color/textDarkColor"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true" />


    </LinearLayout>
</LinearLayout>

4 个解决方案

#1


1  

Remove background from adapter

把背景从适配器

  android:background="@drawable/recyclerview_item_borders"

#2


0  

Recyclerview don't have the divider by default. If you need to add the divider, you have to add the decoration to the recyclerview.

在默认情况下,recycling视图没有分割器。如果您需要添加分隔符,您必须添加装饰到回收视图。

#3


0  

It is from the custom view you are using by default there is no divider. share your code thn any one can help you.

默认情况下,您正在使用的自定义视图没有分隔符。分享你的代码,任何人都可以帮助你。

#4


0  

You need to change it in the List item view. Add following parameters to list item view.

您需要在列表项视图中更改它。向列表项视图添加以下参数。

card_view:cardCornerRadius="0dp"
card_view:cardElevation="0dp" 
card_view:cardUseCompatPadding="true"

In list_item_view.xml

在list_item_view.xml

 <android.support.v7.widget.CardView
  android:id="@+id/card_view"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:layout_gravity="center"
  card_view:cardCornerRadius="0dp"
  card_view:cardElevation="0dp"
  card_view:cardUseCompatPadding="true">

Then set background color of your Recycle view to its foreground color. If it is white,

然后设置循环视图的背景颜色到它的前景颜色。如果它是白色的,

In recycle_view.xml

在recycle_view.xml

<android.support.v7.widget.RecyclerView
  android:id="@+id/recycler_view"
  android:layout_width="match_parent"
  android:background="#ffffff"
  android:scrollbars="vertical"
  android:layout_height="wrap_content"/>

#1


1  

Remove background from adapter

把背景从适配器

  android:background="@drawable/recyclerview_item_borders"

#2


0  

Recyclerview don't have the divider by default. If you need to add the divider, you have to add the decoration to the recyclerview.

在默认情况下,recycling视图没有分割器。如果您需要添加分隔符,您必须添加装饰到回收视图。

#3


0  

It is from the custom view you are using by default there is no divider. share your code thn any one can help you.

默认情况下,您正在使用的自定义视图没有分隔符。分享你的代码,任何人都可以帮助你。

#4


0  

You need to change it in the List item view. Add following parameters to list item view.

您需要在列表项视图中更改它。向列表项视图添加以下参数。

card_view:cardCornerRadius="0dp"
card_view:cardElevation="0dp" 
card_view:cardUseCompatPadding="true"

In list_item_view.xml

在list_item_view.xml

 <android.support.v7.widget.CardView
  android:id="@+id/card_view"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:layout_gravity="center"
  card_view:cardCornerRadius="0dp"
  card_view:cardElevation="0dp"
  card_view:cardUseCompatPadding="true">

Then set background color of your Recycle view to its foreground color. If it is white,

然后设置循环视图的背景颜色到它的前景颜色。如果它是白色的,

In recycle_view.xml

在recycle_view.xml

<android.support.v7.widget.RecyclerView
  android:id="@+id/recycler_view"
  android:layout_width="match_parent"
  android:background="#ffffff"
  android:scrollbars="vertical"
  android:layout_height="wrap_content"/>