java - 安卓游戏: remove padding either side of screen

标签 java android android-studio padding

我对 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/

相关文章:

java - 为什么 Android OS-10 中的 ExoPlayer 在预览时显示黑色预览屏幕

java - 如何在我的应用程序中附加我使用相机拍摄的照片?

java - 这部分代码会在归并排序中执行吗?

android - 整洁架构 : Where to implement pagination logic?

java - 带有局部变量的 Mockito

java - 将 Google map 添加到底部导航栏的按钮

android-studio - Android Studio 3.3.2 注释处理器

Android Studio - 如何从外部库中删除 SDK API?

java - 在 Clojure 中强制垃圾收集是个好主意吗?

Java:为什么编译器会在这里提示?