【问题标题】:Android Layout ResizingAndroid 布局调整大小
【发布时间】:2011-08-03 19:24:25
【问题描述】:

在 android 的游戏中使用相对布局的菜单,但是,启动不同大小的模拟器,即使我使用 dip,布局也不能很好地缩放。在中等屏幕上它工作得很好,但是一个小屏幕会减少一半的底部按钮,而大屏幕会挤压屏幕上的所有按钮,有什么想法吗?

<?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>

【问题讨论】:

  • 请问,什么是不正确缩放的?宽度还是高度?或者更具体地说,哪些视图被“截断”或未正确显示?
  • 最后一个按钮(退出)在较小的屏幕上被切断。宽度很好,高度是问题。

标签: android xml android-relativelayout


【解决方案1】:

也许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"
/>

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

【讨论】:

  • 没问题,如果您觉得有帮助,请记住接受此答案。只需单击此问题旁边的灰色复选标记即可。 :)
【解决方案2】:

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

【讨论】:

  • 有什么方法不需要滚动?
  • 你可以把按钮变小
猜你喜欢
  • 2015-04-30
  • 2012-09-05
  • 2012-02-20
  • 2011-11-20
  • 1970-01-01
  • 2011-10-09
  • 1970-01-01
  • 2014-07-14
  • 1970-01-01
相关资源
最近更新 更多