android動態布局方法總結

2021-07-28 23:56:22 字數 1766 閱讀 2101

言簡意賅,早看到就省不少功夫了

android動態布局方法總結

06wangzl01

//絕對布局

absolutelayout abslayout=new absolutelayout (this);

setcontentview(abslayout);

button btn1 = new button(this);

btn1.settext(」this is a button」);

btn1.setid(1);

absolutelayout.layoutparams lp1 =

new absolutelayout.layoutparams(

viewgroup.layoutparams.wrap_content,

viewgroup.layoutparams.wrap_content,

0,100);

abslayout.addview(btn1, lp1);

//相對布局

relativelayout relativelayout = new relativelayout(this);

setcontentview(relativelayout);

absolutelayout abslayout=new absolutelayout (this);

relativelayout.layoutparams lp1 = new relativelayout.layoutparams(viewgroup.layoutparams.wrap_content, viewgroup.layoutparams.wrap_content);

lp1.addrule(relativelayout.align_parent_top);

lp1.addrule(relativelayout.center_horizontal, relativelayout.true);

relativelayout.addview(abslayout ,lp1);

//線性布局

linearlayout ll = new linearlayout(this);

edittext et = new edittext();

ll.addview(et);

//動態新增布局的方法1.

linearlayout ll = (linearlayout)this.getlayoutinflater().inflate(r.layout.main1,null);

setcontentview(ll);

linearlayout ll2 = (linearlayout)this.getlayoutinflater().inflate(r.layout.main2,ll);

//這樣 main2 作為 main1的子布局 加到了 main1的 根節點下

//動態新增布局的方法2 addview.

linearlayout ll = (linearlayout)this.getlayoutinflater().inflate(r.layout.main1,null);

setcontentview(ll);

linearlayout ll2 = (linearlayout)this.getlayoutinflater().inflate(r.layout.main2,null);

ll.addview(ll2);

android動態布局方法總結

絕對布局 absolutelayout abslayout new absolutelayout this setcontentview abslayout button btn1 new button this btn1.settext this is a button btn1.setid 1 ...

Android 動態布局

android 動態布局 絕對布局 absolutelayout abslayout new absolutelayout this setcontentview abslayout button btn1 new button this btn1.settext this is a button ...

Android布局總結

android的布局的布局型別不多,只有五種。以下是 android的五種布局,我們可以做一些了解。1.linearlayout 線性布局 線性布局可以設定為水平和垂直兩種格式。只能進行單行布局。在布局的使用裡線性布局可以算是用得比較多的一種布局了。1 水平線性布局的話,在一行的位置不足放下元件時會...