Android圖形用戶界面
??上次課我們學習了Activity間如何傳遞數(shù)據(jù)若皱,如何傳遞數(shù)據(jù)以及Activity的生命周期,這次我們學習了UI界面,UI是介于用戶與硬件而設計彼此之間能夠互動溝通的相關軟件,目的在于用戶能夠有效率的去操作硬件飒箭,一達成雙方之間的互動,完成希望借助硬件完成的工作蜒灰。用戶接口定義廣泛锈拨,包含了人機界面與圖形用戶接口购城,凡是參與人類與機械信息交流的領域湊存在用戶接口。
??編寫UI的倆種方式:
?????1.與主程序混合在一起
?????2.寫在XML中(建議使用這種方式)
??用于顯示數(shù)據(jù)居砖,圖片或者其他信息的組建叫做VIEW腾务。
?
???涉及到布局(Layout)和常用控件(View)
?
1毕骡、線性布局和相對布局
2、比較常用的控件View(寬高岩瘦、顏色未巫、邊距、 是否可見启昧、內(nèi)容居中叙凡、在父控件中的位置、點擊事件)
3密末、TextView(顯示文本)握爷、EditText(編輯框 ??屬性inputType 常用事件及特有事件addTextChangedListener)、Button(點擊按鈕) ImageView(src严里、background新啼、scaleType)
?
?
?
2圖形界面的五大布局
五大布局 Layout:
?????LinearLayout ????線性布局
?????RelativeLayout 相對布局
?????AbsoluteLayout 絕對布局
?????GridView 表格布局
?????FrameLayout 幀布局
?
<LinearLayout>線性布局的倆個方向:
???垂直(vertical)
???水平(horizontal)
決定垂直還是水平的屬性為Orientation
?
RelativeLayout 相對布局
android:layout_toRightOf 在指定控件的右邊
android:layout_toLeftOf 在指定控件的左邊
android:layout_above 在指定控件的上邊
android:layout_below 在指定控件的下邊
android:layout_alignBaseline 跟指定控件水平對齊
android:layout_alignLeft 跟指定控件左對齊
android:layout_alignRight 跟指定控件右對齊
android:layout_alignTop 跟指定控件頂部對齊
android:layout_alignBottom 跟指定控件底部對齊
android:layout_alignParentLeft 是否跟父布局左對齊
android:layout_alignParentTop 是否跟父布局頂部對齊
android:layout_alignParentRight 是否跟父布局右對齊
android:layout_alignParentBottom 是否跟父布局底部對齊
android:layout_centerVertical 在父布局中垂直居中
android:layout_centerHorizontal 在父布局中水平居中
android:layout_centerInParent 在父布局中居中
編寫這個程序的代碼:
<LinearLayout?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:paddingBottom="@dimen/activity_vertical_margin"
????android:paddingLeft="@dimen/activity_horizontal_margin"
????android:paddingRight="@dimen/activity_horizontal_margin"
????android:paddingTop="@dimen/activity_vertical_margin"
????tools:context=".MainActivity"
????android:orientation="vertical"
????android:background="#FFFFFF"
????android:gravity="top|left"
????
?????>
???????<LinearLayout
????????android:layout_width="match_parent"
????????android:layout_height="wrap_content"
????????android:orientation="horizontal"
???????>
????<TextView
????????android:layout_width="65dp"
????????android:layout_height="wrap_content"
????????android:text="用戶名"
????????android:textSize="16sp"
?????????/>???
???<EditText?
???????android:layout_width="200dp"
????????android:layout_height="wrap_content"
????????android:hint="請輸入 登錄 用戶名 "
???????/>????????????????
????</LinearLayout>
????<LinearLayout
????????android:layout_width="match_parent"
????????android:layout_height="wrap_content"
????????android:orientation="horizontal"
????????>
????<TextView
????????android:layout_width="65dp"
????????android:layout_height="wrap_content"
????????android:text="密碼"
????????android:textSize="16sp"
?????????/>???
???<EditText?
???????android:layout_width="200dp"
????????android:layout_height="wrap_content"
????????android:hint="請輸入 密碼 "
???????/>????????????????
????</LinearLayout>
<LinearLayout
????????android:layout_width="match_parent"
????????android:layout_height="wrap_content"
????????android:orientation="horizontal"
????????>
????<TextView
????????android:layout_width="65dp"
????????android:layout_height="wrap_content"
????????android:text="年齡"
????????android:textSize="16sp"
?????????/>???
???<EditText?
???????android:layout_width="200dp"
????????android:layout_height="wrap_content"
????????android:hint="請輸入 年齡 "
???????/>????????????????
????</LinearLayout>
<LinearLayout
????????android:layout_width="match_parent"
????????android:layout_height="wrap_content"
????????android:orientation="horizontal"
????????>
????<TextView
????????android:layout_width="65dp"
????????android:layout_height="wrap_content"
????????android:text="生日"
????????android:textSize="16sp"
?????????/>???
???<EditText?
???????android:layout_width="200dp"
????????android:layout_height="wrap_content"
????????android:hint="請輸入 您的生日 "
???????/>????????????????
????</LinearLayout>
<LinearLayout
????????android:layout_width="match_parent"
????????android:layout_height="wrap_content"
????????android:orientation="horizontal"
???????>
????<TextView
????????android:layout_width="65dp"
????????android:layout_height="wrap_content"
????????android:text="電話"
????????android:textSize="16sp"
?????????/>???
???<EditText?
???????android:layout_width="200dp"
????????android:layout_height="wrap_content"
????????android:hint="請輸入 您的電話"
???????/>????????????????
???</LinearLayout>
???<Button
???????android:layout_width="265dp"
???????android:layout_height="wrap_content"
???????android:hint="注冊"
???????android:layout_gravity="center_vertical"
???????/>
</LinearLayout>
編寫這個程序的代碼:
<?xml?version="1.0"?encoding="utf-8"?>
<RelativeLayout?xmlns:android="http://schemas.android.com/apk/res/android"
????android:layout_width="match_parent"
????android:layout_height="match_parent"?>
<ImageView
????android:id="@+id/img1"
????android:layout_width="wrap_content"
????android:layout_height="wrap_content"
????android:src="@drawable/ic_launcher"
????android:layout_centerInParent="true"???
????/>
<ImageView
????android:id="@+id/img2"
????android:layout_width="wrap_content"
????android:layout_height="wrap_content"
????android:src="@drawable/ic_launcher"
????android:layout_above="@id/img1"
????android:layout_centerInParent="true"???
????/>
<ImageView
????android:id="@+id/img3"
????android:layout_width="wrap_content"
????android:layout_height="wrap_content"
????android:src="@drawable/ic_launcher"
????android:layout_alignTop="@id/img1"
????android:layout_toLeftOf="@id/img1"??
????/>
<ImageView
????android:id="@+id/img4"
????android:layout_width="wrap_content"
????android:layout_height="wrap_content"
????android:src="@drawable/ic_launcher"
????android:layout_alignTop="@id/img1"
????android:layout_toRightOf="@id/img1"????
????/>
<ImageView
????android:id="@+id/img5"
????android:layout_width="wrap_content"
????android:layout_height="wrap_content"
????android:src="@drawable/ic_launcher"
????android:layout_below="@id/img1"
????android:layout_centerInParent="true"???
????/>
</RelativeLayout>
????????????????????????????????????????????北京城市學院
????????????????????????????????????????????14通本2班蘇峰