Recyclerview中的粘性物品内容

发布于 2025-02-13 11:48:06 字数 281 浏览 0 评论 0原文

将循环系统的内容粘贴到屏幕侧面的最佳方法是什么?因此,当元素脱离屏幕时,其内容会粘在侧面,并且只有在该孩子的其余元素中没有空间之后才与父母一起使用。

我已经连接了剩下用户滚动的示例,因此RV项目的红色孩子粘在屏幕的左侧。

What is the best way to stick the content of a recyclerview items to the side of the screen. So that when the element goes off screen its content sticks to the side and goes with its parent only after there is no room in the rest of the element for that child.

I've attached the example where user scrolls left, so the red child of rv item is sticked to the left side of the screen.

result

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

耶耶耶 2025-02-20 11:48:06

中尝试此代码

在您的视图持有人Kotlin

itemView.viewTreeObserver.addOnScrollChangedListener {
        val offset  = -itemView.left.toFloat()
        YOUR_RED_VIEW.translationX = offset.coerceAtLeast(0f)
//ELEVATION
        YOUR_RED_VIEW.translationZ = if (offset < 0) 2f else 0f
      
    }

Java

itemView.getViewTreeObserver().addOnScrollChangedListener(() -> {
        float offset = (float) -itemView.getLeft();
        YOUR_RED_VIEW.setTranslationX((float) Math.max(offset,0f));
        //ELEVATION
        YOUR_RED_VIEW.setTranslationZ(offset < 0 ? 2f : 0);
    });

Try this code in your view holder

Kotlin

itemView.viewTreeObserver.addOnScrollChangedListener {
        val offset  = -itemView.left.toFloat()
        YOUR_RED_VIEW.translationX = offset.coerceAtLeast(0f)
//ELEVATION
        YOUR_RED_VIEW.translationZ = if (offset < 0) 2f else 0f
      
    }

Java

itemView.getViewTreeObserver().addOnScrollChangedListener(() -> {
        float offset = (float) -itemView.getLeft();
        YOUR_RED_VIEW.setTranslationX((float) Math.max(offset,0f));
        //ELEVATION
        YOUR_RED_VIEW.setTranslationZ(offset < 0 ? 2f : 0);
    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文