前面我們安裝了Android studio應用並簡單創建了helloworld項目,下面再來進一步學習,也很簡單,學習內容如下:
(1)創建一個簡單的項目,輸出“你好啊,這是我的第一個安卓項目!”
(2)創建項目,使用表格佈局管理器放置組件,界面如下圖所示:
一、創建一個簡單的項目,輸出“你好啊,這是我的第一個安卓項目!”
這個其實很簡單,直接在“activity_main.xml”中修改“TextView”的文本內容就好了,默認是HelloWorld。
然後直接輸出:
二、創建項目,使用表格佈局管理器放置組件,界面如下圖所示。
只需要設計佈局,所以需要在“activity_main.xml”中編寫語句就好了,這裏選擇表格約束,具體代碼如下:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="手 機 號:"
android:textColor="#004"
android:textSize="17sp"
android:paddingLeft="16dp"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="請填寫手機號碼"
android:paddingLeft="8dp"
android:selectAllOnFocus="true"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密 碼:"
android:textColor="#004"
android:paddingLeft="16dp"
android:textSize="16sp"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="請填寫密碼"
android:paddingLeft="8dp"
android:selectAllOnFocus="true"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="確認密碼:"
android:paddingLeft="16dp"
android:textColor="#004"
android:textSize="16sp"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="請確定密碼"
android:paddingLeft="8dp"
android:selectAllOnFocus="true"/>
</TableRow>
<TableRow>
<TextView
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="取消"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="確認"
/>
</TableRow>
</TableLayout>
然後輸出:
over, 這只是簡單的界面佈局的代碼,剛開始嘗試去理解下,後面用Java代碼添加事件纔是難點哦,不過慢慢來總是可以的。