【Android】使用代码动态创建布局

package com.android.myfirstandroidapp;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.LinearLayout;


public class MyFirstAndroidAppActivity extends Activity {
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        // 使用代码动态布局界面的例子
        TextView text1 = new TextView(this);
        text1.setText("Hi there!");
        
        TextView text2 = new TextView(this);
        text2.setText("I'm seconed. I need to wrap.");
        text2.setTextSize( (float)60 );
        
        LinearLayout ll = new LinearLayout(this);
        ll.setOrientation(LinearLayout.VERTICAL);
        ll.addView(text1);
        ll.addView(text2);
        
        setContentView(ll);        

    }
}

你可能感兴趣的:(android)