[英]Android. Weird triangle shadow appearing at the bottom of recycle view list
你沒有發布完整的布局源,但我有同樣的問題,我認為原因是相同的。 我有一個類似的項目列表,每一行都是一個自定義視圖,它擴展了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.