分享

手动添加线性布局,绝对布局 ,添加组件

 Sunny_Gql 2011-08-09
//       //线性布局
        LinearLayout mainLinearLayout = (LinearLayout) this.getLayoutInflater()
        .inflate(R.layout.main, null);
        setContentView(mainLinearLayout);


        EditText editText = new EditText(this);
        editText.setSingleLine(false);
        editText.setGravity(Gravity.LEFT);
        editText.setWidth(50);
        editText.setHeight(50);
        mainLinearLayout.addView(editText, new LinearLayout.LayoutParams(
        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));



  al = new AbsoluteLayout(this);
       
        al.setBackgroundColor(Color.YELLOW);
        // 构造一个 TextView 并设置其 text 和 背景色
       
       
        tv = new TextView(this);
        tv.setText("Android is a software stack for mobile devices that includes an operating system, middleware and key applications. ");
        tv.setBackgroundColor(Color.BLUE);
        // 用该 View 在父 View 中的 width,height,x,y 作为参数构造一个 AbsoluteLayout.LayoutParams
        AbsoluteLayout.LayoutParams tvLP = new AbsoluteLayout.LayoutParams(70, 50, 100, 200);
        // 把这个 TextView 加入到 AbsoluteLayout 中,并应用上一步创建的 LayoutParams。这样 TextView 就会显示在我们指定的位置上了。
        tv.setLayoutParams(tvLP);
       
        al.addView(tv);
        this.setContentView(al);

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约