码迷,mamicode.com
首页 > 其他好文 > 详细

用代码穿件UI

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

标签:android   c   style   class   blog   code   

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

标签:android   c   style   class   blog   code   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!