W3Cschool
恭喜您成為首批注冊用戶
獲得88經驗值獎勵
Activity顯示應用程序的用戶界面,其可以包含諸如按鈕,標簽,文本框等小部件。
通常,你使用XML文件定義UI,例如位于項目的 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>
在運行時,使用Activity
類的setContentView()
方法,在Activity類的onCreate()
方法
處理程序中加載XML UI:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); }
在編譯期間,XML文件中的每個元素都將被編譯為其等效的Android GUI類,其中的屬性由方法表示。
然后,Android系統(tǒng)在加載Activity時創(chuàng)建Activity的UI。
上面的代碼生成以下結果。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: