简体   繁体   English

Android系统。 奇怪的三角形阴影出现在循环视图列表的底部

[英]Android. Weird triangle shadow appearing at the bottom of recycle view list

在此输入图像描述

As you can see on an attached image I'm having a sort of triangle shadow at the right side of my cards down in the list. 正如你在附图中看到的那样,我在卡片右侧的列表中有一个三角形阴影。

I have elevation set to 0 for all three: 我将所有三个的高程设置为0:

app:cardElevation="0dp"
card_view:cardElevation="0dp"
android:elevation="0dp"

This happens to all my lists. 这发生在我的所有列表中。 What am I missing? 我错过了什么?

You didn't post complete layout source, but I had the same issue and I assume the cause was the same. 你没有发布完整的布局源,但我有同样的问题,我认为原因是相同的。 I had a similar list of items, each row being a custom view which extends LinearLayout and inflates some custom layout (let's call it row_item.xml). 我有一个类似的项目列表,每一行都是一个自定义视图,它扩展了LinearLayout并扩展了一些自定义布局(让我们称之为row_item.xml)。 The list layout looked something like this: 列表布局看起来像这样:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <com.example.android.RowItem
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <com.example.android.RowItem
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>

The RowItem layout (row_item.xml) looked something like this: RowItem布局(row_item.xml)看起来像这样:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"
          android:elevation="10dp"
          android:outlineProvider="bounds">

   ...

</LinearLayout>

The problem is RowItem being LinearLayout alone and inflating row_item.xml with the following code: 问题是RowItem单独使用LinearLayout并使用以下代码使row_item.xml膨胀:

LayoutInflater.from(context).inflate(R.layout.row_item, this, true);

This actually wrapped the LinearLayout with elevation by ANOTHER LinearLayout, creating a layout similar to this: 这实际上是通过ANTHER LinearLayout将LinearLayout与高程包装在一起,创建了类似于下面的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">

    <LinearLayout 
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="vertical"
         android:elevation="10dp"
         android:outlineProvider="bounds">

      ...

    </LinearLayout>

</LinearLayout>

Setting elevation on the LinearLayout wrapped by another LinearLayout caused these weird shadows. 在另一个LinearLayout包裹的LinearLayout上设置高程会导致这些奇怪的阴影。 The solution is setting the elevation on the outside LinearLayout. 解决方案是在外部LinearLayout上设置高程。 Even better solution is getting rid of the double layout by replacing <LinearLayout> by <merge> in row_item.xml and setting elevation programmatically inside the custom view's code. 更好的解决方案是通过在row_item.xml中用<merge>替换<LinearLayout>并在自定义视图的代码中以编程方式设置高程来摆脱双重布局。

In case you are not using a custom view but are having this problem, you are probably not setting elevation on the outer most container of your item. 如果您没有使用自定义视图但遇到此问题,则可能未在项目的最外层容器上设置提升。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM