我有一個線性布局。在 Parent 看來,我已經定義了填充。但我想從子視圖中洗掉填充。是否可以洗掉中間的子視圖填充?。我知道一種解決方案是我需要單獨提供填充。但我不想使用這個解決方案。所以任何替代解決方案。
布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tool="http://schemas.android.com/tools"
android:padding="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@ id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:visibility="gone"
tool:text="Header text" />
<View
android:id="@ id/separator"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="10dp"
android:background="#cccccc"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@id/header" />
<androidx.recyclerview.widget.RecyclerView
android:id="@ id/dialog_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp" />
</LinearLayout>
上面的代碼看起來像這樣

預期產出

uj5u.com熱心網友回復:
這可以通過添加 LinearLayout 來完成
android:clipToPadding="false"
并在視圖中設定負水平邊距:
android:layout_marginStart="-16dp"
android:layout_marginEnd="-16dp"
這是有效的,因為你有一個 LinearLayout,似乎除了 LinearLayout 和 RelativeLayout 之外的其他 ViewGroups 不支持負邊距,因為這個答案說:https : //stackoverflow.com/a/10673572/7794806
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/354040.html
