安卓。 recyclerview 列表底部出现奇怪的三角形阴影

标签 android layout android-recyclerview android-cardview

enter image description here

正如您在所附图片中看到的那样,我在列表下方的卡片右侧有一个三角形阴影。

我将所有三个的海拔设置为 0:

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

这发生在我所有的名单上。我错过了什么?

最佳答案

您没有发布完整的布局源,但我遇到了同样的问题,我认为原因是一样的。我有一个类似的项目列表,每一行都是一个自定义 View ,它扩展了 LinearLayout 并扩展了一些自定义布局(我们称之为 row_item.xml)。列表布局看起来像这样:

<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>

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>

问题是 RowItem 是单独的 LinearLayout 并使用以下代码扩充 row_item.xml:

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

这实际上用另一个 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>

在由另一个 LinearLayout 包裹的 LinearLayout 上设置高度会导致这些奇怪的阴影。解决方案是在外部 LinearLayout 上设置高程。更好的解决方案是通过替换 <LinearLayout> 来摆脱双重布局。通过 <merge>在 row_item.xml 中并在自定义 View 的代码中以编程方式设置海拔。

如果您没有使用自定义 View 但遇到了这个问题,您可能没有在项目的最外层容器上设置高度。

关于安卓。 recyclerview 列表底部出现奇怪的三角形阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46609354/

相关文章:

android - 可以设置debug/AndroidManifest.xml

java - Android 项目(4.4.2)在 eclipse 和 adt 更新后未运行

android - 如何在 RealmRecyclerViewAdapter 中实现可过滤

html - 如何创建固定高度的第一列布局?

java - 让 Java Swing 程序重新布局自身

android - 导航项更改不会更新回收站 View

android - 由于 firebase 数据库的异步特性,无法从 firebase 数据库检索数据

java - 当用户选择今天之前的日期时,Android Java 显示错误消息

android - 我应该扩充布局还是以编程方式创建它?

html - 几个带圆 Angular 的嵌套 DIV