欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

android動態(tài)布局,安卓動態(tài)布局

android 如何動態(tài)布局自定義view,不用XML.

可以直接new View來得到View對象來實現(xiàn)代碼布局。以下為示例代碼:

成都創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),礦區(qū)企業(yè)網(wǎng)站建設(shè),礦區(qū)品牌網(wǎng)站建設(shè),網(wǎng)站定制,礦區(qū)網(wǎng)站建設(shè)報價,網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,礦區(qū)網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強企業(yè)競爭力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學習、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。

1.絕對布局

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);

2.相對布局

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);

3.線性布局

LinearLayout ll = new LinearLayout(this);

EditText et = new EditText();

ll.addView(et);

//動態(tài)添加布局的方法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的 根節(jié)點下

//動態(tài)添加布局的方法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 動態(tài)布局與靜態(tài)布局的優(yōu)缺點?

動態(tài)布局,也就是可以根據(jù)業(yè)務(wù)的需求改變界面。實際上就是用代碼寫出界面,代碼量比較大。而且維護起來十分的繁瑣。特別是一些界面空間比較多的時候。靜態(tài)的布局,是通過xml來實現(xiàn)的,適用于頁面比較固定的情況。但是維護起來比較方便。

android 動態(tài)設(shè)置布局寬度

例如設(shè)置一個圖片寬高 關(guān)鍵代碼:

//取控件當前的布局參數(shù)

LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) imageView.getLayoutParams();

//設(shè)置寬度值

params.width = dip2px(MainActivity.this, width);

//設(shè)置高度值

params.height = dip2px(MainActivity.this, height);

//使設(shè)置好的布局參數(shù)應用到控件

imageView.setLayoutParams(params);

1

2

3

4

5

6

7

8

1

2

3

4

5

6

7

8

高度除了可以設(shè)置成以上固定的值,也可以設(shè)置成wrap_content或match_content

ViewGroup.LayoutParams.WRAP_CONTENT

ViewGroup.LayoutParams.MATCH_PARENT

1

2

1

2

在這里插入圖片描述

xml

android 如何實現(xiàn)動態(tài)添加布局

如下代碼:

LinearLayout layout = new LinearLayout(this);

TextView tx = new TextView(this);

tx.setText('我是動態(tài)添加的');

layout.addView(tx);

setContentView(layout);

這就動態(tài)添加了一個線性布局,并且在布局里面加了一個textview

文章名稱:android動態(tài)布局,安卓動態(tài)布局
地址分享:http://www.chinadenli.net/article46/dsdgoeg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)網(wǎng)站營銷企業(yè)網(wǎng)站制作手機網(wǎng)站建設(shè)電子商務(wù)全網(wǎng)營銷推廣

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設(shè)計