【发布时间】:2011-12-21 00:40:52
【问题描述】:
最近,我一直在开发我的第一个 android 应用程序,该应用程序可以在不同的温度单位之间进行转换。我已经完成了所有实际的编码,但我在为其创建 GUI 时遇到了问题。我一直在使用 DroidDraw UI builder 来生成 xml 代码;在 DroidDraw 内部,我在整个 UI 中都使用了 RelativeLayout。当我在 DroidDraw 中创建它时,它在预览中看起来不错,但是当我尝试运行该应用程序时,它总是看起来基本上是一团糟:
这是否与不同屏幕尺寸的要求有关,如果是,我该如何解决?
添加一些额外的信息,我不是通过模拟器运行它;我在具有 480x800 屏幕的 captivate 上运行它。此外,我正在使用带有 NBAndroid 插件的 NetBeans IDE 进行构建。
这是我的 [main.xml][2] 文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/widget32"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<EditText
android:id="@+id/input"
android:layout_width="100px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_alignTop="@+id/output"
android:layout_alignParentLeft="true"
>
</EditText>
<TextView
android:id="@+id/widget42"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Output"
android:layout_below="@+id/ftok"
android:layout_alignLeft="@+id/ktoc"
>
</TextView>
<TextView
android:id="@+id/widget41"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Input"
android:layout_below="@+id/ftok"
android:layout_alignParentLeft="true"
>
</TextView>
<Button
android:id="@+id/ftok"
android:layout_width="104px"
android:layout_height="wrap_content"
android:text="Far To Kel"
android:textStyle="bold"
android:layout_alignTop="@+id/ctok"
android:layout_alignParentLeft="true"
>
</Button>
<Button
android:id="@+id/ctok"
android:layout_width="104px"
android:layout_height="wrap_content"
android:text="Cel To Kel"
android:textStyle="bold"
android:layout_alignTop="@+id/ktoc"
android:layout_alignLeft="@+id/ctof"
>
</Button>
<Button
android:id="@+id/ktoc"
android:layout_width="104px"
android:layout_height="wrap_content"
android:text="Kel To Cel"
android:textStyle="bold"
android:layout_below="@+id/ctof"
android:layout_alignParentRight="true"
>
</Button>
<Button
android:id="@+id/ctof"
android:layout_width="104px"
android:layout_height="wrap_content"
android:text="Cel To Far"
android:textStyle="bold"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
>
</Button>
<Button
android:id="@+id/ktof"
android:layout_width="104px"
android:layout_height="wrap_content"
android:text="Kel To Far"
android:textStyle="bold"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
>
</Button>
<Button
android:id="@+id/ftoc"
android:layout_width="104px"
android:layout_height="wrap_content"
android:text="Far To Cel"
android:textStyle="bold"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
>
</Button>
<TextView
android:id="@+id/widget50"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Temperature Conversion is Fun!"
android:textSize="16sp"
android:textStyle="bold"
android:layout_below="@+id/widget49"
android:layout_toRightOf="@+id/widget41"
>
</TextView>
<TextView
android:id="@+id/widget49"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Kel=Kelvin"
android:layout_below="@+id/widget48"
android:layout_alignLeft="@+id/ctok"
>
</TextView>
<TextView
android:id="@+id/widget48"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cel=Celcius"
android:layout_below="@+id/widget47"
android:layout_alignLeft="@+id/ctok"
>
</TextView>
<TextView
android:id="@+id/widget47"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Far=Fahrenheit"
android:layout_below="@+id/input"
android:layout_alignLeft="@+id/ctok"
>
</TextView>
<EditText
android:id="@+id/output"
android:layout_width="100px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_below="@+id/widget42"
android:layout_toRightOf="@+id/ctok"
>
</EditText>
</RelativeLayout>
任何帮助将不胜感激。
【问题讨论】:
标签: android xml user-interface android-relativelayout