我是编码的新手,想要学习真的很糟糕
我在developer.android.com网站上自学。
不幸的是,我遇到了一个泥潭,无法通过这段代码
请帮忙。我做错了什么?
如果你想看看这里的练习是地址:
http://developer.android.com/training/basics/firstapp/building-ui.html#Button
<?xml version="1.0" encoding ="utf-8" ?>
<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:orientation="horizontal" />
<EditText android:id="@+id/edit_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send" />
</LinearLayout>
答案 0 :(得分:1)
您的问题在这里:
<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:orientation="horizontal" />
请注意,您有
/>
这会关闭线性布局标记。它应该是这样的:
<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:orientation="horizontal" >
without the closing /
注意:
如果您使用的是Linux,那么确定您是否正确复制教程中的代码的一种非常简单的方法就是使用Meld。我将你的代码复制到一个文件名1中,教程代码放在一个名为2的文件中,然后做了“meld 1 2”,结果用户界面显示了你的错误,而我甚至不必思考
编辑:
首先 - 融合窗户;
关于你的问题:
@String/edit_message
您需要在应用程序的字符串资源中定义此值。以下内容摘自
http://developer.android.com/guide/topics/resources/string-resource.html
FILE LOCATION:
res/values/filename.xml // in oyur case this will likely be Strings.xml
The filename is arbitrary. The <string> element's name will be used as the resource ID.
COMPILED RESOURCE DATATYPE:
Resource pointer to a String.
RESOURCE REFERENCE:
In Java: R.string.string_name
In XML:@string/string_name
SYNTAX:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string
name="string_name" // in your case this will be name="edit_message"
>text_string</string>
</resources>
如果文件不存在,您可以在以下位置创建:
/res/values/strings.xml
定义你的价值等等,一切都应该修复。