如何删除默认布局的填充/边距

时间:2015-03-31 09:33:05

标签: android android-layout

我有以下布局文件:

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像素。

以下图片enter image description here

上的箭头说明了这一点

如何强制布局不添加这些填充/边距?

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

Activiy

 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();
    }
}

我在任何地方都不使用任何尺寸...... THKS

2 个答案:

答案 0 :(得分:29)

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

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

答案 1 :(得分:1)

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

相关问题