我有以下布局文件:
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 像素的填充或边距。
如何强制布局不添加这些填充/边距?
编辑:我应该添加插入 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/