【问题标题】:Multiple layers of shadows in android recyclerview elevationandroid recyclerview海拔中的多层阴影
【发布时间】:2016-02-03 16:37:07
【问题描述】:

我有一个高度为 8dp、透明背景和边界的 recyclerview 作为 outlineProvider。 clipToPadding 在父 relativelayout 上设置为 false。我正面临一个奇怪的问题 w.r.t 投下的阴影 回收站视图海拔。阴影似乎覆盖了 recyclerview 的边缘,或者在 relativelayout 和子 recyclerview 之间有一个额外的层(附加图像参考)。究竟是什么导致了这种影响?我搜索了很多,但找不到任何解释。欢迎提出任何建议。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_grid_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false">

<android.support.v7.widget.RecyclerView
    android:id="@+id/grid_recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="110dp"
    android:layout_marginLeft="15dp"
    android:layout_marginTop="80dp"
    android:background="@color/transparent"
    android:outlineProvider="bounds"
    android:elevation="8dp"
    android:padding="0dp"
    android:scrollbars="none" />


<ImageView
    android:id="@+id/grid_main_filter_id"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:layout_alignBottom="@+id/grid_recycler_view"
    android:layout_alignStart="@+id/grid_recycler_view"
    android:layout_marginBottom="-18dp"
    android:layout_marginStart="67dp"
    android:elevation="10dp"
    android:background="@drawable/main_filter" />

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentStart="true"
    android:layout_marginBottom="36dp"
    android:layout_marginLeft="27dp"
    android:src="@drawable/hive" />

<ImageView
    android:id="@+id/imageView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="36dp"
    android:layout_marginLeft="24dp"
    android:layout_toEndOf="@+id/imageView2"
    android:src="@drawable/sway" />

<ImageView
    android:id="@+id/imageView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="36dp"
    android:layout_marginLeft="24dp"
    android:layout_toEndOf="@+id/imageView3"
    android:src="@drawable/colony" />

<ImageView
    android:id="@+id/imageView5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="36dp"
    android:layout_marginLeft="24dp"
    android:layout_toEndOf="@+id/imageView4"
    android:src="@drawable/vault" />

<ImageView
    android:id="@+id/imageView6"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_marginBottom="36dp"
    android:layout_marginRight="28dp"
    android:src="@drawable/camera" />

<ProgressBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/progressBar"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:visibility="gone"/>

recycler_view_child_item

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="0dp">
<ImageView
    android:id="@+id/thumbnail"
    android:layout_width="84dp"
    android:layout_height="150dp"
    android:layout_margin="0dp"
    android:padding="0dp" />
</LinearLayout>

【问题讨论】:

    标签: android android-layout android-view android-recyclerview android-elevation


    【解决方案1】:

    第一个阴影由 RecyclerView 投射,第二个阴影由第一个 ImageView 子级投射到 RecyclerView 之上。两个阴影看起来都很好。也许您可以突出显示图像中您认为不正确的部分?

    【讨论】:

    • 编辑了问题。 recyclerview 子项没有任何高度。
    • 对不起,我还是不明白它有什么问题。
    • recyclerview 的子项(recycler_view_child_item)没有任何高程。所以它不能在recyclerview上投下任何阴影。那么第二个影子是从哪里来的呢?如果我仍然不清楚我的问题,请告诉我。
    • 它可能来自图像 grid_main_filter_id
    • 也检查过。这不是原因。透明背景似乎是导致问题的原因,因为当我将背景更改为不同时,阴影效果完美。但我只需要 recyclerview 的透明背景,所以还不知道该怎么做才能修复它。类似问题stackoverflow.com/questions/32286229/…
    【解决方案2】:

    阴影不在 RecyclerView 的顶部,而是在 RecyclerView 的后面。这个阴影是可见的,因为你有 RecyclerView 的透明背景。阴影在 RecyclerView 下渲染,但不是整个表面都被绘制,只是边缘周围的一些区域。

    这可能是一种优化或副作用,我不确定,但我一直在观察这种“效果”。我想这是正常的和有意的。如果你做一个纯色的背景,不好看的部分会被覆盖。

    【讨论】:

      猜你喜欢
      • 2015-08-22
      • 2015-02-13
      • 1970-01-01
      • 2017-10-15
      • 2015-02-14
      • 2016-11-11
      • 1970-01-01
      • 2018-07-09
      • 2017-07-13
      相关资源
      最近更新 更多