我对 Android 比较陌生,正在制作一款非常基本的游戏。我想知道如何删除主游戏屏幕两侧的填充,以便游戏将占据正在使用的任何设备的整个屏幕。
我原本以为这与dimens.xml文件有关:
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
我尝试将这两个值更改为 0dp,但白色填充仍然保留在屏幕上。 另外 - 在activity_play_game.xml中我有以下内容:
android:layout_width="match_parent"
android:layout_height="match_parent"
我想这可能与此有关?有人知道我哪里出错了吗? 非常感谢!
最佳答案
将此添加为您的 Activit 布局。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black">
</RelativeLayout>
您应该看到整个屏幕充满黑色。然后尝试将其添加到里面
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:text="Margin Padding Test" />
并尝试将android:padding="20dp"
和android:layout_margin="20dp"
添加到RelativeLayout和TextView中。当您尝试这些属性的不同组合时,您应该能够更新布局以使其符合您的需要。
边距更改布局在其父级中的定位方式。
填充改变布局在其内部的定位方式。
关于java - 安卓游戏: remove padding either side of screen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31773494/