Android 布局调整大小

发布于 2024-11-27 21:55:22 字数 1610 浏览 2 评论 0原文

然而,在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小镇女孩 2024-12-04 21:55:22

也许RelativeLayout 并不是这里的最佳选择。我要做的是在垂直方向使用 LinearLayout 。使用 weight 可以让元素均匀分布,无论屏幕大小如何。也许,尝试这样的事情:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Button android:id="@+id/new_game"
    android:layout_width="200dp"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:text="feasdf"
/>
<Button android:id="@+id/instructions"
    android:layout_width="200dp"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:text="feasdf"
/>
<Button android:id="@+id/exit_game"
    android:layout_width="200dp"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:text="feasdf"
/>

如果您还有其他问题,请告诉我!

Perhaps a RelativeLayout is not the best choice here. What I would do is use a LinearLayout in a vertical direction. Using weight you can make it so that allow the elements are evenly spaced out no matter the screen size. Perhaps, try something like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Button android:id="@+id/new_game"
    android:layout_width="200dp"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:text="feasdf"
/>
<Button android:id="@+id/instructions"
    android:layout_width="200dp"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:text="feasdf"
/>
<Button android:id="@+id/exit_game"
    android:layout_width="200dp"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:text="feasdf"
/>

Let me know if you've got any other questions!

贱贱哒 2024-12-04 21:55:22

RelativeLayout 放入 ScrollView 文档。这将在较小的屏幕尺寸上显示被切除的部分。它不会影响更大的屏幕尺寸,所有内容都可以在屏幕上查看。

Put the RelativeLayout into a ScrollView 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文