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

标签 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 比如

fragment 初始化.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

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

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

Activity

 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>

关于android - 如何删除默认布局的填充/边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29365268/

相关文章:

android - 使用部分字符串匹配进行 Firebase 查询

android - 如何恢复 Android ListView 的位置?

安卓扩展apk

Android Studio 3.1.3 不显示布局设计预览

android - 拆分 AndroidStudio 的 XML/文本和设计窗口

android获取picasa图片网址

Android - 响应协助请求

android - 检查 JSONArray 的特定值

java - 在 Java 和 XML 中使用自定义布局

android - 如何在 Android XML 布局文件中放置按钮,就像在 GridView 中一样