android - RecyclerView 不要在角落夹住项目

标签 android android-recyclerview

我想使 recyclerView 圆角,但如果子项目有背景颜色,它会覆盖到 recyclerView 并且无法被剪裁。这是设计 如果我删除项目的背景颜色,那么它可能就像我的设计一样。但不幸的是,有时它有蓝色背景

Design

这是我的应用程序显示的内容 Here is what my app show

这是我的项目布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/item_popover"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/dp_8"
    android:background="@color/white"
    tools:ignore="RtlHardcoded,RtlSymmetry"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <com.jp.base.customView.AppImageView
        android:id="@+id/img_notification"
        android:paddingRight="@dimen/dp_8"
        app:srcCompat="@mipmap/ic_launcher_round"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginStart="@dimen/dp_8"
        android:layout_marginEnd="@dimen/dp_8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <android.support.v7.widget.AppCompatImageView
        android:id="@+id/img_arrow"
        app:srcCompat="@drawable/ic_keyboard_arrow_right_blue_24dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <com.jp.base.customView.AppTextView
        android:id="@+id/tv_message"
        tools:text="Message....\nMessage"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toEndOf="@id/img_notification"
        app:layout_constraintEnd_toStartOf="@id/img_arrow"
        android:maxLines="5"
        android:layout_marginTop="@dimen/dp_5"
        android:textColor="@color/black"
        android:layout_width="0dp"
        android:layout_height="wrap_content" />

    <com.jp.base.customView.AppTextView
        android:id="@+id/tv_time"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/dp_8"
        android:drawablePadding="@dimen/dp_8"
        android:gravity="center_vertical"
        android:textSize="@dimen/text_small"
        app:app_leftDrawable="@drawable/ic_access_time_black_24dp"
        app:layout_constraintHorizontal_bias="0"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/img_arrow"
        app:layout_constraintStart_toEndOf="@id/img_notification"
        app:layout_constraintTop_toBottomOf="@+id/tv_message"
        app:layout_constraintVertical_bias="100"
        tools:text="a month ago" />

    <View
        app:layout_constraintTop_toBottomOf="@id/tv_time"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_marginTop="@dimen/dp_8"
        android:background="@color/gray"
        android:layout_width="0dp"
        android:layout_height="0.5dp" />

</android.support.constraint.ConstraintLayout>

我的 RecyclerView:

<android.support.v7.widget.RecyclerView
            android:id="@+id/list_notification"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_marginTop="-30dp"
            android:background="@drawable/rect_bound_bottom_5dp"
            android:clipChildren="true"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/tv_popup_title"
            tools:listitem="@layout/item_popover" />

最佳答案

我会尝试:

  • 在 Recycler View 上设置“round rect”轮廓 - setOutline

  • 这通常与“高程”一起用于提供阴影效果,但如果您不需要阴影 - 您可以跳过高程部分

  • 最后在 RecyclerView 上再次调用 setClipToOutline

关于android - RecyclerView 不要在角落夹住项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50466396/

相关文章:

android - 使用MVVM在RecyclerView的网格和线性之间切换的更好方法是什么?

android - 如何在 android 中的 Recyclerview 上添加页眉/页脚

android - 如何处理回收站 View 中的空数据?

java - 创建Fragment时缺少参数

java - new Runnable(){} 类型的 findViewById(int) 方法未定义

java - RecyclerView 应用崩溃

java - Android RecyclerView 不回收项目

android - 简单的 osmdroid 应用程序不起作用

android - Firebase 云消息系统 UI 已停止

android - 防止 Android 中的 Fragment 恢复