欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

手写android布局示例

程序员文章站 2023-11-08 14:35:22
复制代码 代码如下:package com.test; import android.app.activity;import android.os.bundle;//im...

复制代码 代码如下:

package com.test;

import android.app.activity;
import android.os.bundle;
//import android.view.view;
import android.widget.button;
import android.widget.linearlayout;
//import android.widget.toast;

public class test_javaactivity extends activity {

        @override
        public void oncreate(bundle savedinstancestate) {
                super.oncreate(savedinstancestate);

                linearlayout layout = new linearlayout(this);
                // layout.setorientation(linearlayout.vertical);

                button button = new button(this);

                button.settext("click me");

                button.setlayoutparams(new linearlayout.layoutparams(
                                linearlayout.layoutparams.fill_parent,
                                linearlayout.layoutparams.wrap_content));

/**                button.setonclicklistener(new view.onclicklistener() {
                        @override
                        public void onclick(view v) {
                                toast.maketext(test_javaactivity.this, "button clicked",
                                                toast.length_long).show();
                        }
                });
*/
                layout.addview(button);
                setcontentview(layout);
        }
}