【问题标题】:Mask items in recycler view with drawable (background)使用可绘制(背景)在回收站视图中屏蔽项目
【发布时间】:2018-08-16 21:59:20
【问题描述】:

是否有一种简单的方法可以在回收站视图中屏蔽项目? 我制作了一个灰色笔触和 20 角半径的可绘制实体。 笔触在顶部/机器人/侧面看起来不错,但圆角会被回收物品切割掉。

有解决此问题的常见做法吗?

【问题讨论】:

  • 我可以增加填充,但我不想在以后调整它。也许我可以使背景透明,但分隔线仍会超出角落。理想的方法是在 XML 文件中有某种屏蔽选项。到目前为止我还没有找到。
  • 它们是如何切割的?有图片吗?
  • 你能发一些你提到的问题的截图吗?任何表示您想要的视觉方式也可能有助于给出答案
  • 添加了一张图片。
  • 您的回收站视图是否有任何海拔?对我来说,这看起来像是 Zindex 问题。我会尝试设置android:transformZ="5dp" 或任何高于您的 RV 高度的东西。

标签: android android-recyclerview background


【解决方案1】:

我刚遇到同样的问题,我知道这个答案晚了 8 个月,但我仍然会提供我想出的答案。

对于我的 RecyclerView,我已经有圆角图标,我用它作为背景:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <corners
        android:bottomLeftRadius="40dp"
        android:bottomRightRadius="10dp"
        android:topLeftRadius="10dp"
        android:topRightRadius="40dp"
        />
    <size
        android:width="480dp"
        android:height="480dp"/>
    <solid
        android:color="@color/colorAccent"/>
</shape>

然后,我用它作为前景(它就像一个面具):

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <corners
        android:bottomLeftRadius="40dp"
        android:bottomRightRadius="10dp"
        android:topLeftRadius="10dp"
        android:topRightRadius="40dp"
        />
    <size
        android:width="500dp"
        android:height="500dp"/>
    <stroke
        android:width="10dp"
        android:color="@color/colorAccent"/>
</shape>

然后您可以在轮廓的粗细上进行播放,并为 RecyclerView 添加一些填充。

希望对你有所帮助,^_^。

快乐编码;

【讨论】:

    猜你喜欢
    • 2022-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-14
    相关资源
    最近更新 更多