我正在关注这个Android tutorial 。我正在尝试查找 main.xml
但它不在 res/layout
中。我确实有 res/layout/activity_my_first.xml
但该文件的根节点是 RelativeLayout
而不是像教程中的 LinearLayout
。 如何获取main.xml?
也许我可以自己创建它。或者也许我拥有的 XML 文件是较新版本的 ADT 插件中 main.xml 的替代品。我是 Android 和 Eclipse 的新手,所以我有点卡住了。
干杯!
最佳答案
您只需将 Activity_my_first.xml 中的内容替换为教程中的内容即可。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_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>
或创建另一个名为 main.xml 的 xml。本教程假设您已经创建了我猜测的内容。
只需确保在您的 Activity 的 onCreate 方法中您有
setContentView(R.layout.activity_my_first);
关于android - 新 Android 项目中缺少 main.xml - Eclipse OS X,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11369048/