[Android]在代码中创建布局

package com.swufe.layout;

import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;

public class SecondPage extends Activity {
private LayoutParams lp;
private LinearLayout ll;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.page_0);
lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);

TextView myTextView = new TextView(this);
myTextView.setText("Hello!");

ll.addView(myTextView);

this.addContentView(ll,lp);

}
}
原文地址:https://www.cnblogs.com/shocker/p/2435846.html