導航:首頁 > 編程語言 > relativelayout代碼

relativelayout代碼

發布時間:2025-04-26 23:50:35

❶ android 布局xml中 android:fitsSystemWindows="true" 這一句是什麼意思有什麼作用

簡單的講:設置應用布局時是否考慮系統窗口布局;如果為true,將調整系統窗口布局以適應你自定義的布局。比如系統有狀態欄,應用也有狀態欄時。看你這個布局代碼,恰恰是在定義標題欄樣式,所以用到這行代碼了。

❷ Android中怎麼用純代碼編寫布局

一、用RelativeLayout進行純代碼布局的理論基礎
1、RelativeLayout,顧名思義,就是以「相對」位置/對齊 為基礎的布局方式。
2、android.widget.RelativeLayout 有個繼承自android.view.ViewGroup.LayoutParams 的內嵌類 LayoutParams,使用這個類的實例
調用RelativeLayout.addView 就可以實現「相對布局」。 android.widget.RelativeLayout.LayoutParams 有一個構造函數:
RelativeLayout.LayoutParams(int w, int h),參數指定了子 View 的寬度和高度,這一點和其父類是一樣的。而實現相對布局的關
鍵在它的 兩個 addRule 方法上。anchor 參數指定可以是View 的 id(「相對於誰」)、RelativeLayout.TRUE(啟用某種對齊方式) 或者
是-1(應用於某些不需要 anchor 的 verb);AddRule 方法的 verb 參數指定相對的「動作」(以下常量均定義於
android.widget.RelativeLayout中,為了簡便不給出其全名):
3、ALIGN_BOTTOM、ALIGN_LEFT、 ALIGN_RIGHT、 ALIGN_TOP: 本 View 的 底邊/左邊/右邊/頂邊 和 anchor 指定的 View 的
底邊/左邊/右邊/頂邊 對齊。
ALIGN_WITH_PARENT_BOTTOM 、ALIGN_WITH_PARENT_LEFT 、 ALIGN_WITH_PARENT_RIGHT 、
ALIGN_WITH_PARENT_TOP : 和上面一組常量類似,只不過不需要再指定 anchor, 其 anchor 自動為 Parent View。
CENTER_HORIZONTAL、CENTER_IN_PARENT 、CENTER_VERTICAL : 如果 anchor 為 TRUE,在 Parent 中 水平居中/水平
和垂直均居中/垂直居中。
POSITION_ABOVE 、POSITION_BELOW 、 POSITION_TO_LEFT 、POSITION_TO_RIGHT : 本 View 位於 anchor 指定的 View
的上邊/下邊/左邊/右邊。

安卓開發 怎麼動態修改應用名稱代碼

RelativeLayout layout =(RelativeLayout) findViewById(R.id.layout);
Button but = new Button(this);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(50,50);
lp.addRule(RelativeLayout.ALIGN_TOP,R.id.button);
lp.addRule(RelativeLayout.ALIGN_RIGHT,R.id.button);
layout.addView(but, lp);

關鍵是 addRule 方法 看代碼很顯然,是指定對齊button的頂端和右端。

另一種思路是,先在xml里配置好兩個button。不過先把上面的button的visibility 設置為gone,用到的時候在java代碼里設置為visible。

❹ android 如何動態布局自定義view,不用XML.

可以直接new View來得到View對象來實現代碼布局。以下為示例代碼:
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);
//動態添加布局的方法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);

閱讀全文

與relativelayout代碼相關的資料

熱點內容
cnc圓弧怎麼樣編程 瀏覽:199
java二叉堆 瀏覽:850
少兒編程後會怎麼樣 瀏覽:783
ps去掉掃描文件無效部分 瀏覽:191
快速創建文件夾路徑路徑 瀏覽:849
京東app虛擬試衣 瀏覽:136
三星電視智能升級卡 瀏覽:327
word文件字型大小 瀏覽:460
word文檔去除下劃線 瀏覽:576
貝多芬交響曲版本 瀏覽:532
下載的視頻文件損壞了 瀏覽:119
怎麼把jpg轉成cad格式的文件大小 瀏覽:674
如何編程真人快打 瀏覽:57
double運行數據最長多少 瀏覽:367
tr90如何看數據 瀏覽:418
word裡面插了一個文件怎麼打開 瀏覽:40
蘋果7限時秒殺1999元 瀏覽:748
如何提升app推送觸達率 瀏覽:584
vba用kill刪除文件路徑錯誤 瀏覽:648
linux查看10個文件總大小 瀏覽:423

友情鏈接