mainactivity.java
 package com.example.codeui1;import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class MainActivity extends Activity {
public TextView text2;
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FrameLayout frameLayout=new FrameLayout(this);
frameLayout.setBackground(this.getResources().getDrawable(R.drawable.ic_launcher));
setContentView(frameLayout);
TextView text1=new TextView(this);
text1.setText("代码中构建UI界面");
text1.setTextSize(TypedValue.COMPLEX_UNIT_PX,24);
text1.setTextColor(Color.rgb(1,1,1));
frameLayout.addView(text1);
text2=new TextView(this);
text2.setText("单击进入游戏,不要后悔!!!!!!");
text2.setTextSize(TypedValue.COMPLEX_UNIT_PX,24);
text2.setTextColor(Color.rgb(1,1,1));
LayoutParams params=new LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
params.gravity=Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM;
text2.setLayoutParams(params);
text2.setOnClickListener(new OnClickListener(){ @Override
public void onClick(View v) {
new Builder(MainActivity.this).setTitle("警告信息")
.setMessage("自我毁灭程序即将启动,确定启动?")
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO 自动生成的方法存根
Log.i("1.1","进入游戏了");
}
}).setNegativeButton("QUIT",
new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO 自动生成的方法存根
Log.i("1.1","离开游戏了");
finish();
}
}).show();
// TODO 自动生成的方法存根

}

});
frameLayout.addView(text2);
} @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;
}}
用java代码控制Ui界面中的控件布局总是不成功,控件的布局总是默认的,控件布局的代码已经用红色字体标出,请问问题出在哪里了布局控件