Android 布局调整大小
然而,在 Android 游戏上使用相对布局的菜单,启动不同大小的模拟器,并且布局根本无法很好地缩放,即使我使用的是 dial。在中型屏幕上它工作正常,但是小屏幕会切掉一半底部按钮,而大屏幕会挤压屏幕上方的所有按钮,有什么想法吗?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/menubackground"
>
<Button
android:text="High Scores"
android:layout_height="wrap_content"
android:layout_width="200dp"
android:id="@+id/HighScore"
android:layout_below="@+id/NewGame"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:textStyle="bold"
></Button>
<Button
android:text="Instructions"
android:layout_height="wrap_content"
android:layout_width="200dp"
android:id="@+id/Instructions"
android:layout_below="@+id/HighScore"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:textStyle="bold"
></Button>
<Button
android:text="Exit"
android:layout_height="wrap_content"
android:layout_width="200dp"
android:id="@+id/Exit"
android:layout_below="@+id/Instructions"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:textStyle="bold"
>
</Button>
<Button android:layout_height="wrap_content"
android:textStyle="bold"
android:id="@+id/NewGame"
android:text="New Game"
android:layout_width="200dp"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/HighScore"
android:layout_marginTop="191dp"></Button>
</RelativeLayout>
Using a relative layout for a menu on a game for android, however, launching different size emulators and the layout doesn't scale at all well even though i'm using dip. On a medium screen it works fine, however a small screen cuts half the bottom buttons off and the large screen scrunches all the buttons further up the screen, any ideas?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/menubackground"
>
<Button
android:text="High Scores"
android:layout_height="wrap_content"
android:layout_width="200dp"
android:id="@+id/HighScore"
android:layout_below="@+id/NewGame"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:textStyle="bold"
></Button>
<Button
android:text="Instructions"
android:layout_height="wrap_content"
android:layout_width="200dp"
android:id="@+id/Instructions"
android:layout_below="@+id/HighScore"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:textStyle="bold"
></Button>
<Button
android:text="Exit"
android:layout_height="wrap_content"
android:layout_width="200dp"
android:id="@+id/Exit"
android:layout_below="@+id/Instructions"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:textStyle="bold"
>
</Button>
<Button android:layout_height="wrap_content"
android:textStyle="bold"
android:id="@+id/NewGame"
android:text="New Game"
android:layout_width="200dp"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/HighScore"
android:layout_marginTop="191dp"></Button>
</RelativeLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许RelativeLayout 并不是这里的最佳选择。我要做的是在垂直方向使用 LinearLayout 。使用
weight
可以让元素均匀分布,无论屏幕大小如何。也许,尝试这样的事情:如果您还有其他问题,请告诉我!
Perhaps a
RelativeLayout
is not the best choice here. What I would do is use aLinearLayout
in a vertical direction. Usingweight
you can make it so that allow the elements are evenly spaced out no matter the screen size. Perhaps, try something like this:Let me know if you've got any other questions!
将
RelativeLayout
放入ScrollView
文档。这将在较小的屏幕尺寸上显示被切除的部分。它不会影响更大的屏幕尺寸,所有内容都可以在屏幕上查看。Put the
RelativeLayout
into aScrollView
documentation. This will display the part that is being cut off on smaller screen sizes. It won't affect larger screen sizes where all the content can be viewed on the screen.