消除回收者视图行之间的空隙

时间:2017-10-30 09:33:30

标签: android android-studio android-recyclerview

好的,我环顾四周,没有发现这个特殊情况。

我有一个垂直的recyclerView,在线性布局中(所以android:height设置为0dp,以支持权重功能)。此recyclerView包含几乎无限的日期列表。当用户滚动时,当前日期(如果需要,则为行)将其背景更改为透明,以显示它是当前日期。我后来才注意到,项目行不适合recyclerView为该行提供的所有空间。 如果你看到图像,一切都会更清晰:我突出一个小而小的行,不同的颜色(不是白色)。这是recyclerView背景! 所以,我的问题是,为什么项目布局不适合所有行空间?

enter image description here

另外:这是recyclerView xml:

   <android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="6.0"
    android:elevation="5dp"
    android:background="@drawable/background_recycler_view_main"/>

这就是行:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/row_day"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="180dp"
android:background="@color/white">

<View
    android:id="@+id/vertical_row"
    android:layout_width="3dp"
    android:layout_height="match_parent"
    android:background="@color/budget_remains"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_marginStart="40dp"
    android:layout_marginLeft="40dp"/>

<TextView
    android:id="@+id/day_number0"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/vertical_row"
    android:layout_toEndOf="@id/vertical_row"
    android:layout_marginLeft="10dp"
    android:layout_marginStart="10dp"
    android:layout_marginTop="10dp"
    android:gravity="bottom"
    android:text="@string/day_number_fake"
    android:textColor="@color/day_number_and_name"
    android:textSize="@dimen/day_number" />

<TextView
    style="@style/DayInfoMain"
    android:id="@+id/day_name0"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@id/day_number0"
    android:layout_marginBottom="5dp"
    android:layout_marginLeft="5dp"
    android:layout_marginStart="5dp"
    android:layout_toEndOf="@id/day_number0"
    android:layout_toRightOf="@id/day_number0"
    android:text="@string/day_name_fake" />

<TextView
    style="@style/AmountDayAndExpense"
    android:id="@+id/day_amount0"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@id/day_name0"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_marginEnd="16dp"
    android:layout_marginRight="16dp"
    android:text="@string/day_amount_fake"
    android:textSize="@dimen/day_text" />

并根据要求提供background_recycler_view_main:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:type="radial"
    android:startColor="@color/white"
    android:endColor="@color/background_main_component"
    android:gradientRadius="200dp"/>
</shape>

2 个答案:

答案 0 :(得分:0)

它看起来像不同项目之间的分隔线。 在您创建Recyclerview实例的类中尝试此操作 我假设实例是这样的

if(b instanceof C) {
     ((C) b).fun2();
}

然后在下方添加此行以使分隔符为空

Recyclerview mRecyclerView = (Recyclerview) findviewbyId(R.id.recycler_view);

答案 1 :(得分:0)

提升导致shadow effect的{​​{1}}。从回收站视图中删除此行代码

recycler items
相关问题