W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
Activity顯示應(yīng)用程序的用戶界面,其可以包含諸如按鈕,標(biāo)簽,文本框等小部件。
通常,你使用XML文件定義UI,例如位于項(xiàng)目的 res/layout
文件夾中的main.xml
文件。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="hello" /> </LinearLayout>
在運(yùn)行時(shí),使用Activity
類的setContentView()
方法,在Activity類的onCreate()
方法
處理程序中加載XML UI:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); }
在編譯期間,XML文件中的每個(gè)元素都將被編譯為其等效的Android GUI類,其中的屬性由方法表示。
然后,Android系統(tǒng)在加載Activity時(shí)創(chuàng)建Activity的UI。
上面的代碼生成以下結(jié)果。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: