Android 如何消除子元素中的父填充

Android 如何消除子元素中的父填充,android,android-layout,Android,Android Layout,我有FrameLayout,对于大多数片段,parrent填充效果很好。但我有一个特殊的碎片,里面不能有填充物 任何建议 奇怪的是,仅仅使用layout\u margin似乎不起作用。但是, <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="

我有FrameLayout,对于大多数片段,parrent填充效果很好。但我有一个特殊的碎片,里面不能有填充物



任何建议

奇怪的是,仅仅使用
layout\u margin
似乎不起作用。但是,

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:padding="10dp"
         android:clipToPadding="false">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="-10dp"
        android:layout_marginStart="-10dp"
        android:layout_marginEnd="-10dp"
        android:layout_marginBottom="-10dp" />
</FrameLayout>

似乎有效(IntelliJ android预览版)


别忘了:
在父布局中,安卓:clipToPadding=“false”

如果您只需从框架布局中删除
安卓:padding=“10dp”
,在“正常”片段中添加10dp填充,而在“特殊”片段中不添加任何填充,事情就会变得更简单。可以使用负边距,但我认为只有在没有其他方法的情况下才应该使用负边距。

错误:(3)在包“android”ups中找不到属性“margin”的资源标识符,抱歉,修复了答案。虽然没有明确回答我的问题,但这很有用。TextView的父级使用可绘制图形作为其背景。可绘制背景的存在会自动将填充添加到子文本视图中,通过将父文本填充设置为0dp解决了这一问题。是的,这是一种方法,但它是常规的。另一种方法是,当我选择espesial fragment时,以编程方式设置填充。但另一只手更优雅,不需要代码