package com.example.demo03linearlayoutdemo;import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.view.ViewGroup;import android.widget.LinearLayout;import android.widget.TextView;public class MainActivity extends Activity { //编程实现LinearLayout @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);// LinearLayout linearLayout = new LinearLayout(this);// //quick key alt+cmd+v// LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);//////// layoutParams.setLayoutDirection(LinearLayout.VERTICAL);//// LinearLayout.LayoutParams txtParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);// TextView textView = new TextView(this);// textView.setLayoutParams(txtParams);// textView.setText("wwww.baidu.com");// textView.setTextSize(20);//// linearLayout.addView(textView,txtParams);// super.addContentView(linearLayout,layoutParams); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }