【问题标题】:Android game: remove padding either side of screenAndroid游戏:删除屏幕两侧的填充
【发布时间】:2015-10-24 17:53:47
【问题描述】:

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

我认为这可能与它有关?有人知道我哪里出错了吗? 非常感谢!

【问题讨论】:

    标签: java android android-studio padding


    【解决方案1】:

    将此添加为您的 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 中。当您尝试这些属性的不同组合时,您应该能够根据需要更新布局。

    边距改变布局在其父级中的定位方式。

    填充改变布局在自身内部的定位方式。

    【讨论】:

    • 很好的答案!在玩了不同的组合之后,我把它整理好了!谢谢:D
    猜你喜欢
    • 2017-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-23
    • 2023-02-25
    • 2018-10-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多