代码:

 

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

 

public class ActivityMain extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);       
        setContentView(R.layout.main);
        TextView tv=new TextView(this);
        tv.setText("Hello World");
        setContentView(tv);
    }
}

 

 

 

运行效果如下所示:

 

第一个android程序(helloworld)_bundle

界面显示HelloWorld

是由于代码中有:

 TextView tv=new TextView(this);
        tv.setText("Hello World");
        setContentView(tv);

同时在main.xml中有

<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />

有对TextView  的描述。

fill_parent:充满整个父窗口
wrap_content:根据组件的内容自动调整组件大小