今天开始正式开始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>
效果如下图:
