【问题标题】:Ripple not drawable over other view波纹不能在其他视图上绘制
【发布时间】:2019-11-12 13:38:09
【问题描述】:

我有一个回收站视图,并且我正在扩展另一个视图作为此回收站视图的一个项目。左右每个项目都需要一定的填充/边距,但我希望波纹在屏幕的整个宽度上可见(回收站视图宽度适合屏幕)。

代码 -

  <android.support.v7.widget.RecyclerView
      android:id="@+id/recycler_view"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:paddingStart="20dp"
      android:paddingEnd="20dp"
      android:background="@android:color/transparent"
      android:clipChildren="false"
      android:clipToPadding="false"/>

Recycler View Item XML

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:drawSelectorOnTop="true"
    android:orientation="vertical">
...

</LinearLayout>

从这段代码中,ripple 只延伸到 Recycler View Item XML 宽度。

我已经尝试将此填充移动到 Recycler View Item XML 并且它可以工作。但是有没有其他选择,我基本上不想移动paddingStart和paddingEnd。

这些我都试过了——

  1. android:background="@android:color/transparent"
  2. android:clipChildren="假" android:clipToPadding="假"
  3. android:drawSelectorOnTop="true"

【问题讨论】:

  • 确保您的 recyclerview 项目布局没有任何填充并使用背景作为 ?attr/selectableItemBackground
  • 不使用任何填充,我认为它不会影响它。我试过使用 selectableItemBackground
  • 会发生什么?您在 >21 台设备上进行测试吗?
  • Ripple 没有扩展到整个屏幕。是的。
  • 你能分享一下项目布局xml吗?

标签: android android-layout android-recyclerview


【解决方案1】:

确保您的 recyclerview 项目布局没有任何边距并且宽度与父级匹配

添加父项布局背景,如下所示

android:background="?attr/selectableItemBackground"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-21
    • 1970-01-01
    相关资源
    最近更新 更多