如何删除默认布局的填充/边距 [英] How to remove default layout's padding/margin

查看:168
本文介绍了如何删除默认布局的填充/边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下布局文件:

activity_main.xml

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>

还有其他一些片段,例如

And some other fragments like

fragment_init.xml:

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

Everything looks fine in Lint, but when I execute my application on my Nexus 7 5.0.2, every container is displayed with a padding or margin of maybe 10 px.

这由下图上的箭头所示

This is illustrated by the arrows on the following image

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

How to force the layouts to not add these padding/margin?

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

I should add how I insert my fragment.

活动

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

我在任何地方都不会使用任何调光... 谢谢

and I don't use any dimens anywhere... Thks

推荐答案

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

Go into this file res/values/dimens.xml and change the values to 0dp just like in the code below.

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

这篇关于如何删除默认布局的填充/边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆