3

我正在尝试做第一个应用程序教程。在编辑了 2 个 xml 文件、activity_main 和字符串之后,说明说:“在 Eclipse 中,单击工具栏中的运行。”

首先,它向我展示了一些问题。将 EditText 设置为 时android:layout_weight="1",它不喜欢android:layout_height设置为wrap_content并在“问题”选项卡上显示我。如果我像宽度一样将 layout_height 设置为 0dp,问题就会消失。

其次,现在它在问题列表中没有显示任何内容,无论是在 Windows 计算机上还是在通过 USB 连接并根据前面的说明进行设置的我的 android 设备上,点击运行都不会做任何事情。

我发现另一个有类似问题的线程。他们建议他查看他的 AndroidManifest.xml 和 MainActivity.java。我的似乎包含他们建议需要在那里的东西。哦!我看到我的狂热是开放的,但它似乎什么也没说。

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >
    <EditText android:id = "@+id/edit_message"
        android:layout_weight="1"
        android:layout_width = "0dp"
        android:layout_height = "0dp"
        android:hint="@string/edit_message"/>
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text = "@string/button_send"/>
</LinearLayout>

字符串.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">My First App</string>
    <string name="action_settings">Settings</string>
    <string name="edit_message">Edit your message, silly.</string>
    <string name="button_send">Send</string>
    <string name="title_activity_man">MainActivity</string>

</resources>
4

5 回答 5

8

当您在 XML 文件上时,Eclipse 中的“运行”按钮不起作用。打开其中一个 .java 文件,然后点击 Run - 它应该编译并运行应用程序。

于 2013-07-26T21:19:09.987 回答
1

创建一个 AVD 以使用模拟器或确保您的手机被 eclipse 检测到。还可以转到运行配置,为 Android 应用程序创建一个新配置并选择您的 Android 项目。

于 2013-07-27T01:04:38.247 回答
0

无法重现此错误:

首先,它向我展示了一些问题。将 EditText 设置为 android:layout_weight="1",它不喜欢将 android:layout_height 设置为“wrap_content”并在“问题”选项卡上显示。

即使您的应用程序运行,它也只会在显示屏右侧显示按钮。将EditText不可见。这是因为您将EditText's高度设置为0dp

由于您正在设置to的layout_weight属性,并且方向是(默认情况下),您只需要设置 to 的宽度。这将使按钮占用尽可能多的宽度,其余部分由按钮占用,其宽度设置为 wrap_content。EditText1LinearLayout'shorizontalEditText0dpEditText

这应该可以帮助您了解使用时的选项LinearLayoutsLinearLayout.LayoutParams

于 2013-07-26T20:32:27.913 回答
0

男孩这不是问题。您只需选择您的应用程序并将其作为 android 应用程序运行。此外,检查 AVD 管理器是否已启动并运行虚拟机。如果没有,请先启动它。假设您已经创建了 AVD。现在转到主要活动并点击运行按钮和 yupiee。=P

于 2013-07-26T22:31:24.670 回答
0

我将假设您使用的是 Eclipse。你真的启动了你的虚拟设备吗?当我创建我的第一个项目时,我创建了虚拟设备但忘记实际单击开始。当我点击运行时,什么也没发生。

尝试右键单击您的项目并转到 Run As -> Android App。

于 2013-07-26T20:40:00.167 回答