如果您完全确定您的内容将适合显示器,并且您只想将其置于布局中,假设您的游戏大小为(例如 320x200),您可以从以下内容开始:
只需创建一个带有根 FrameLayout 的 xml 布局文件(将其视为指针:我没有测试此代码):
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#000000"
android:layout_width="match_parent"
android:layout_height="match_parent">
<YourView
android:id="@+id/myview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
</FrameLayout>
游戏内容要居于屏幕中央,“YourView”的黑边会溢出屏幕。
希望这可以帮助
注意:编辑了 layout_width/height 参数(因为在其中设置内容大小会产生不正确的结果,除非您的视图尊重类似于 android:gravity 参数的内容)。