首页 > 其他 > 详细

用代码穿件UI

时间:2014-06-09 20:07:05      阅读:281      评论:0      收藏:0      [点我收藏+]

android中有时候需要用代码穿件ui

bubuko.com,布布扣
public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        LinearLayout layout = new LinearLayout(getApplicationContext());

        layout.setOrientation(LinearLayout.VERTICAL);
        TextView tv = new TextView(getApplicationContext());
        // tv.setText("代码创建UI");
//设置控件的显示特性 tv.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
tv.setText(
"代码创建UI"); Button bt = new Button(getApplicationContext()); bt.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); bt.setText("show"); layout.addView(tv); layout.addView(bt); super.setContentView(layout); bt.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Toast.makeText(getApplicationContext(), "use code create UI", 1) .show(); } }); } }
bubuko.com,布布扣

 

用代码穿件UI,布布扣,bubuko.com

用代码穿件UI

原文:http://www.cnblogs.com/kevinhuspace/p/3777116.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!