安卓应用程序图形用户界面

发布于 2024-12-22 14:06:05 字数 5153 浏览 3 评论 0原文

最近,我一直在开发我的第一个 Android 应用程序,该应用程序可以在不同的温度单位之间进行转换。我已经掌握了所有实际的编码,但在为其创建 GUI 时遇到了问题。我一直在使用 DroidDraw UI 生成器来生成 xml 代码;在 DroidDraw 内部,我在整个 UI 中使用relativelayout。当我在 DroidDraw 中创建它时,它在预览中看起来很好,但当我尝试运行该应用程序时,它总是最终看起来基本上是一团乱麻:

screenshot

这是否与不同屏幕尺寸的要求有关,如果是,我该如何解决?

添加一些额外的信息,我没有通过模拟器运行它;我在我的 captivate 上运行它,屏幕分辨率为 480x800。另外,我正在使用带有 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>

任何帮助将不胜感激。

Recently I've been working on my first android app that converts to and from different units of temperatures. I have all the actual coding down pat, but I'm having an issue creating a GUI for it. I've been using the DroidDraw UI builder to generate the xml code; Inside of DroidDraw I'm using RelativeLayout throughout the entire UI. Whenver I create it in DroidDraw it looks fine in the preview, but when I try to run the app, it always ends up looking like basically a jumbled mess:

screenshot

Does this have anything to due with requirements for different screen sizes, and if so, how can I fix it?

Adding some extra information, I'm not running it through an emulator; I'm running it on my captivate which has a 480x800 screen. Also, I'm building using the NetBeans IDE with the NBAndroid Plugin.

Here's my [main.xml][2] file:

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

Any help would be much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

输什么也不输骨气 2024-12-29 14:06:05

我以前从未使用 droiddraw 进行现实世界布局,只是下载它来测试一下。
据我所知:我不建议使用它。

所有生成的布局默认使用 px 作为指定视图大小的单位。就 Android 布局而言,这是一个非常糟糕的想法(由于周围有许多屏幕尺寸/密度)并且几乎永远不需要(我还没有找到有用的布局)。更糟糕的是,我无法在属性选项卡中指定任何其他单位。

这会导致您所看到的确切问题。布局在其设计的屏幕尺寸上看起来正确,但在其他屏幕上却严重失败。

我建议手动编写 XML。或者,如果您更愿意使用所见即所得编辑器,请使用 eclipse ADT 插件,该编辑器最近改进了很多。

I never used droiddraw for real world layouts before and just downloaded it to test a bit around.
And from what I see: I would not recommend using it.

All the generated layouts use px by default as a unit to specify view sizes. That is a very bad idea in terms of android layouts (due to the many screen sizes/densities around) and should almost never be neccessary (I have yet to find a layout where that's useful). And even worse, I can't specify any other unit in the properties tab.

That leads to the exact problems you are seeing. Layouts which look correct on the screen size they were designed for and horribly failing on every other screen.

I recommend writing XML by hand. Or if you rather use a WYSIWYG editor, use the eclipse ADT plugin, that editor improved a lot recently.

佞臣 2024-12-29 14:06:05

由于 Dalvik 虚拟机很大程度上基于 Java 虚拟机,而我是一名 Java 程序员,因此我可以提供一些建议。如果 droid API 具有与 JPanel 等效的功能,请使用面板来组织内容(看起来您可能已经这样做了)。另外,检查框架是否具有“refresh()”类型的函数 - 通常这有助于告诉窗口相应地组织内容。

Since the Dalvik Virtual Machine is heavily based on the Java Virtual Machine and I'm a Java Programmer, I can offer a little advice. If the droid API has an equivalent to JPanel, organize stuff with Panels (it looked like you may do that already). Also, check to see if the frame has a "refresh()" type of function - Usually that helps to tell the window to organize stuff accordingly.

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