今天開始正式開始Android的學習之路,作爲一名Java EEer,在自己學有餘力之時算是一個知識的拓展吧,也力爭做向複合型程序員前進。
入門教程還是郭霖的那本《第一行代碼》,幾個小時把Activity、layout都過了一遍,文風清晰易懂,速度很快但理解思維可以跟得上,特別是涉及到不同活動之間的數據傳遞等在有了web開發之後,可以進行對比性的理解,實現的原理感覺都相似。
佈局這塊大概的歸納下:AbsoluteLayout、RelativeLayout、LinearLayout、FrameLayout、TableLayout、GridLayout.
而TableLayout是LinearLayout的子類。(中文分別是:絕對佈局、相對佈局、線性佈局、幀佈局、表格佈局、網格佈局)
在2.2操作系統中將AbsoluteLayout過期。而目前FrameLayout、TableLayout也逐漸被過去。只推薦使用RelativeLayout、LinearLayout兩種佈局。
下面簡單的實現一個登陸註冊功能的佈局:
1.activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#33DEDBD7"
>
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="@drawable/relative_bg" >
<EditText
android:id="@+id/edit_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/shape"
android:singleLine="true"
android:inputType="number"
android:ems="10"
android:hint="@string/phone" >
</EditText>
<EditText
android:id="@+id/edit_pass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/shape"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/edit_user"
android:inputType="numberPassword"
android:ems="10"
android:hint="@string/password" />
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignLeft="@+id/edit_user"
android:layout_below="@+id/edit_user"
android:background="#DEDBD7" />
<TextView
android:id="@+id/TextView01"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignBottom="@+id/edit_pass"
android:layout_alignParentLeft="true"
android:background="#DEDBD7" />
<ImageView
android:id="@+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/description"
android:layout_alignLeft="@+id/TextView01"
android:layout_below="@+id/edit_pass"
android:src="@drawable/login" />
</RelativeLayout>
</RelativeLayout>
2.shape.xml(放在drawable下,用於去除輸入框的邊框等)
<shape xmlns:android="http://schemas.android.com/apk/res/android"
>
<!-- 填充的顏色:這裏設置背景透明 -->
<solid android:color="@android:color/transparent" />
<!-- 邊框的顏色 :不能和窗口背景色一樣-->
<stroke
android:width="3dp"
android:color="#ffffff" />
<!-- 設置按鈕的四個角爲弧形 -->
<!-- android:radius 弧形的半徑 -->
<corners android:radius="5dip" />
<!-- padding:Button裏面的文字與Button邊界的間隔 -->
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
</shape>
效果如下圖: