簡體   English   中英

Android系統。 奇怪的三角形陰影出現在循環視圖列表的底部

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

在此輸入圖像描述

正如你在附圖中看到的那樣,我在卡片右側的列表中有一個三角形陰影。

我將所有三個的高程設置為0:

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

這發生在我的所有列表中。 我錯過了什么?

你沒有發布完整的布局源,但我有同樣的問題,我認為原因是相同的。 我有一個類似的項目列表,每一行都是一個自定義視圖,它擴展了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);

這實際上是通過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>

在另一個LinearLayout包裹的LinearLayout上設置高程會導致這些奇怪的陰影。 解決方案是在外部LinearLayout上設置高程。 更好的解決方案是通過在row_item.xml中用<merge>替換<LinearLayout>並在自定義視圖的代碼中以編程方式設置高程來擺脫雙重布局。

如果您沒有使用自定義視圖但遇到此問題,則可能未在項目的最外層容器上設置提升。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM