2012-07-06 60 views
2

我跟随此Android tutorial。我试图找到main.xml,但它不在res/layout。我确实有res/layout/activity_my_first.xml但是这个文件的根节点是RelativeLayout而不是LinearLayout,就像本教程中一样。 如何获取main.xml?在新的Android项目中缺少main.xml - Eclipse OS X

也许我可以自己创建它。或者,也许我拥有的XML文件是ADT插件新版本中main.xml的替代品。我是全新的Android和Eclipse,所以我有点卡住了。

干杯!

回答

1

您可以将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。本教程假设您已经创建了即时猜测。

只需确保在您的活动的onCreate方法你有

setContentView(R.layout.activity_my_first); 
1

不需要标题为“main.xml”的布局。如果你愿意,你可以在你的res/layout文件夹中创建一个名为main.xml的文件,然后在你的示例中复制并粘贴布局 - 然后它就可以在代码中使用了。但是,除非您尝试在您的java代码中使用名为“main”的布局,否则您的项目中不需要使用布局。