【问题标题】:Android. Weird triangle shadow appearing at the bottom of recycle view list安卓。 recyclerview 列表底部出现奇怪的三角形阴影
【发布时间】:2017-10-06 15:40:55
【问题描述】:

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

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

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

这发生在我的所有列表中。我错过了什么?

【问题讨论】:

  • 您是否尝试过更改背景并检查它是否仍然可用?
  • 是的,我尝试了不同的背景设置。都一样
  • 这通常是高程/阴影的问题。仔细检查所有相关布局中的标高,并确保您没有从代码中应用标高(看起来您在代码中做了一些事情,因为每行都会增加)
  • 项目整体布局的邮政编码和onBindViewHolder方法

标签: android layout android-recyclerview android-cardview


【解决方案1】:

您没有发布完整的布局源代码,但我遇到了同样的问题,我认为原因是相同的。我有一个类似的项目列表,每一行都是一个自定义视图,它扩展了 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 上设置高程。更好的解决方案是通过在 row_item.xml 中将 &lt;LinearLayout&gt; 替换为 &lt;merge&gt; 并在自定义视图的代码中以编程方式设置高度来摆脱双重布局。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多