項目二智慧城市界面實現-任務2購物信息儲存開發_第1頁
項目二智慧城市界面實現-任務2購物信息儲存開發_第2頁
項目二智慧城市界面實現-任務2購物信息儲存開發_第3頁
項目二智慧城市界面實現-任務2購物信息儲存開發_第4頁
項目二智慧城市界面實現-任務2購物信息儲存開發_第5頁
已閱讀5頁,還剩18頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

任務實現知識準備任務目標項目2智慧城市界面的實現任務2購物信息的界面開發購物信息的

界面,用于顯示用戶的訂單號,收貨人,聯系電話及聯系地址及總額,并以二維表的形式顯示商品名稱,數量和單價。本任務是主要完成該界面的開發。【任務目標】掌握TableLayout布局的使用方法掌握Spinner控件的使用(用于支付方式)方法1.TableLayout布局的使用【知識準備】表格布局與常見的表格類似,以行列的方式來管理放入其中的組件。表格布局采用<TableLayout>標記,在其中通過添加<TableRow>標記來表示行。同時,<TableRow>也是容器,所以可以向該標記中添加其他組件,每添加一個組件,表格就會增加一列。在表格布局中,

可以設置相應的屬性,來控制列的收縮與隱藏。表格布局的基本語法格式如下:/apk/res/android"<TableLayoutxmlns:android="http://s屬性列表>組件列表</TableLayout>【知識準備】XML屬性說明andriod:collapseColumns設置需要隱藏的列的序列號(序號從0開始),多個用列序號用逗號“,”隔開。android:shrinkColumns設置允許被收縮的列的序列號(序號從0開始),多個用列序號用逗號“,”隔開。android:stretchColimns設置允許被拉伸的列的序列號(序號從0開始),多個用列序號用逗號“,”隔開。TableLayout常見的XML屬性列表1.TableLayout布局的使用2.Spinner控件的使用【知識準備】Android中提供了Spinner控件(列表選擇框)使用Spinner相當于從下拉列表中選擇項目,供用戶進行選擇。Spinner的繼承結構比較復雜,在繼承樹中有AdapterView,這是比較重要的。因此

就是通過Adapter來為Spinner設置下拉列表項的。Spinner的重點問題就是下拉列表項的配置,通過之前組件的了解,

知道資源組件的配置有兩種方式,一種是通過XML文件來配置,一種是通過程序來配置。而從Spinner的文檔中,

可以看到,對它的配置需要使用Adapter類的實現。【知識準備】Spinner控件(列表選擇框)的基本語法格式如下:<Spinner屬性列表></Spinner>表2.4

Spinner常見的XML屬性列表XML屬性說明andriod:entries為可選屬性,用于指定列表項,如果在布局文件中不指定該屬性,可以在Java代碼中通過為其指定適配器的方式指定android:protmpt為可選屬性,用于指定列表框的標題【任務實現】在Eclipse下創建一個Android項目,命名為AndroidDemo2.2,實現購物車的支付功能界面的開發。1.修改res/layout

下的布局文件,首先添加一個水平的線性布局管理器,在該布局管理器中嵌套添加一個相對布局管理器,代碼如下:<RelativeLayout

android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_margin="30dp"android:background="@drawable/bg_frame_descend_small”android:orientation="vertical"

></RelativeLayout>【任務實現】2.在其人”、“添加五個TextView控件,分別顯示:“訂單號”、”收貨

”、“收貨地址”和“總金額”等信息。具體代碼如下:<TextViewandroid:id="@+id/textView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"http://與父容器的左邊緣對齊android:layout_alignParentTop="true"http://與父容器的上邊緣對齊android:layout_marginLeft="50dp"http://與左邊緣的距離是50dpandroid:layout_marginTop="30dp"http://與上邊緣的距離是30dpandroid:text="訂單號:201508260528"

//顯示的文本android:textColor="@color/white"

/>//文本的顏色 資源文件中的color/white<TextView

android:id="@+id/textView2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@+id/textView1"android:layout_below="@+id/textView1"android:layout_marginTop="8dip"【任務實現】android:text="收貨人:

"android:textColor="@color/white"

/><TextView

android:id="@+id/textView3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@+id/textView2"android:layout_below="@+id/textView2"android:layout_marginTop="8dip"android:text="

:136********"android:textColor="@color/white"

/><TextView

android:id="@+id/textView4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@+id/textView3"android:layout_below="@+id/textView3"android:layout_marginTop="8dip"android:text="收獲地址:XX省XX市XX縣XX街道"

android:textColor="@color/white"/>【任務實現】<TextViewandroid:id="@+id/textView5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@+id/textView4"android:layout_below="@+id/textView4"android:layout_marginTop="8dip"android:text="總金額:114"android:textColor="@color/white"/>【任務實現】3.在該相對布局管理器中,再添加一個表格布局管理器和兩個TableRow控件。在第一個TableRow中添加四個TextView控件,分別顯示商品名稱、商品數量及單價并且在最后一個TextView中設置該控件的描邊和填充屬性等。其代碼如下:<TableLayoutandroid:id="@+id/tableLayout1"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_alignLeft="@+id/textView5"http://與組件textView5的左邊緣對齊android:layout_below="@+id/textView5"http://在組件textView5的下方

android:layout_centerVertical="true"http://位于垂直居中的位置

android:layout_marginRight="50dp"android:layout_marginTop="8dip"><TableRow //添加一個TableRow即增加一行

android:id="@+id/tableRow1"android:layout_width="wrap_content"android:layout_height="wrap_content">【任務實現】<TextViewandroid:layout_width="0.0dp"android:layout_height="wrap_content"android:layout_weight="2" //該組件的權重為2android:background="@drawable/sh

_table"http://設置TextView組件的背景

為drawable/sh

_tableandroid:text="商品名稱"

android:textColor="@color/white"/><TextView_table"android:layout_width="0.0dp"android:layout_height="wrap_content"android:layout_weight="2"android:background="@drawable/shandroid:text="商品數量"

android:textColor="@color/white"/><TextView_table"android:layout_width="0.0dp"android:layout_height="wrap_content"android:layout_weight="1"android:background="@drawable/shandroid:text="單價"

android:textColor="@color/white"/><TextView【任務實現】android:layout_width="0.0dp"android:layout_height="wrap_content"android:layout_weight="5"_table"

/>android:background="@drawable/sh</TableRow>【任務實現】4、在第二個TableRow中添加四個TextView控件,分別顯示"伊利暢輕牛奶"及設置其他三個組件的描邊和填充屬性等。其代碼如下:<TableRowandroid:id="@+id/tableRow2"android:layout_width="wrap_content"android:layout_height="wrap_content"

><TextViewandroid:layout_width="0.0dp"android:layout_height="wrap_content"_table"_table"android:layout_weight="2"android:background="@drawable/shandroid:text="伊利暢輕牛奶"

android:textColor="@color/white"/><TextViewandroid:layout_width="0.0dp"android:layout_height="wrap_content"android:layout_weight="2"android:background="@drawable/shandroid:text="50"android:textColor="@color/white"

/><TextViewandroid:layout_width="0.0dp"android:layout_height="wrap_content"【任務實現】android:layout_weight="1"android:background="@drawable/sh

_table"android:text="2"android:textColor="@color/white"

/><TextViewandroid:layout_width="0.0dp"android:layout_height="wrap_content"android:layout_weight="5"_table"

/>android:background="@drawable/sh</TableRow></TableLayout>【任務實現】5、在外層的相對布局管理器中添加一個Spinner控件和一個Button按鈕用于下拉列表的顯示等功能,具體代碼如下:<Spinnerandroid:layout_height="wrap_content"android:layout_width="wrap_content"android:layout_below="@+id/tableLayout1"http://該組件位于tableLayout1的下部android:id="@+id/spinner"android:layout_marginTop="10dp"http://該組件距上邊緣的距離為10dpandroid:layout_alignRight="@+id/tableLayout1"/><Buttonandroid:id="@+id/button1"android:layout_width="30dp"

//button組件的寬度為30dp【任務實現】android:layout_height="30dp"

//button組件的高度為30dpandroid:layout_alignRight="@+id/tableLayout1"android:layout_below="@+id/spinner"android:layout_marginTop="10dp"android:background="@drawable/btn_return_normal"/>【任務實現】6、在res\values下新建一個名為spinner的xml文件,在資源文件中定義添加一個資源

,定義string-array數組,添加item項,實際上是定義列表選擇框中的內容。具體代碼如下:<?xml

version="1.0"

encoding="utf-8"?><resources><string-array

name="mode">

//定義string-array數

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論