2012-07-14 161 views
1

我正在通过使用最新SDK的上的MyFirstApp教程。Android元素不显示

我创建了一个4.1应用程序,并设置了我的仿真器,其LCD密度为213,VM应用程序堆为48,设备RAM大小为512.分辨率为720x1280。

当我第一次得到这个时,我的“Android”在模拟器上闪现。

我注意到,我的布局main.xml中没有被默认创建的,所以我在res /布局添加它自己

添加以下的main.xml和strings.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_height="wrap_content" 
     android:layout_weight="1" 
     android:layout_width="0dp" 
     android:hint="@string/edit_message" /> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/button_send" /> 
</LinearLayout> 



<resources> 
    <string name="app_name">My First App</string> 
    <string name="edit_message">Enter a message</string> 
    <string name="button_send">Send</string> 
</resources> 

现在当我运行我的模拟器时,我只是得到一个黑屏。我的猜测是,我没有正确添加main.xml或者我的xml文件中有错误。

+0

你做的setContentView(R.layout.main)方法( )你的活动的方法? – 2012-07-14 11:22:50

+0

iam试着让你的代码完美工作.. – NagarjunaReddy 2012-07-14 11:36:48

+0

@SiddharthLele你对活动的评论指出我的方向是正确的,我没有在启动向导中正确设置它。如果您发布答案,我会接受它。 – Liath 2012-07-14 11:48:23

回答

2

通过在活动的onCreate()方法使用以下statemetn地图XML文件(main.xml中)到你的活动:在您的onCreate

setContentView(R.layout.main);