如何删除默认布局的 padding/margin

How to remove default layout's padding/margin

我有以下布局文件:

activity_main.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:id="@+id/frame_container"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginLeft="0px"
    android:layout_marginRight="0px"
    android:layout_marginTop="0px"
    android:padding="0dp"
    >
    ...
</FrameLayout>

还有一些其他片段,例如

fragment_init.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/fragmentInit"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="0dp"
    android:layout_marginTop="0px"
    android:layout_marginLeft="0px"
    android:layout_marginRight="0px"
    android:background="#549F07"
    >

    <TextView
        ... 
    >
    ...
</RelativeLayout>

在 Lint 中一切看起来都很好,但是当我在我的 Nexus 7 5.0.2 上执行我的应用程序时,每个容器都显示有可能为 10 像素的填充或边距。

下图中的箭头说明了这一点

如何强制布局不添加这些 padding/margin?

编辑:我应该添加插入片段的方式。

活动

 public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        fragmentTransaction.replace(R.id.frame_container, new Fragment_init(), "Fragment_init").commit();
    }
}

而且我在任何地方都不使用任何尺寸... 谢谢

进入此文件 res/values/dimens.xml 并将值更改为 0dp,就像在下面的代码中一样。

<dimen name="activity_horizontal_margin">0dp</dimen>
<dimen name="activity_vertical_margin">0dp</dimen>

我知道这个问题已经回答了,但是,我刚遇到这样的问题,答案有帮助但不完全,因为有一个正确的填充。我发现,这是因为我使用的主题中设置了填充。这可能对那些仍然看到填充的人有帮助。您需要做的就是将其删除。