对布局(Relative Layout)
在此界面的底部采用了相对布局,用来固定下面两个按钮"修改密码""重新登录"的位置,此处将他们位置分别固定在左下角和右下角。这两个按钮也引用了背景图片。
这八个按钮起到的就是导航的作用,无论对本系统是否了解只要了解Android下的软件的使用方法就可以轻松使用。
除了相对布局和线性布局意外,还有其他布局,这些布局在其他的界面中均有使用,如表格布局(Table Layout)。
图 5.2 功能主界面
5.2.2 此界面系统流程图
在功能主界面中所叙述的主要功能如上面所述,把上面的所有功能整理为程序流程图如图5.3所示。在本模块中,开始处的判断指的是进入此界面后点击的是哪一个按钮,而在结尾处的判断是否结束处指的是用户是否选择退出程序。
图 5.3 欢迎屏幕流程图
5.2.3主要代码实现
此功能主界面的布局代码:
xmlns:android="schemas.android/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background_login">
android:orientation="vertical"
android:layout_marginTop="70dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
android:id="@+id/login_div1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dip"
android:orientation="horizontal"
android:padding="15dip" >
android:id="@+id/login_div2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dip"
android:orientation="horizontal"
android:padding="15dip" >
android:layout_weight="1"
android:id="@+id/button_what"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="@drawable/dingsun" />
android:layout_weight="1"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="@drawable/xitong" />
android:layout_weight="1"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="@drawable/fuwu" />
android:layout_width="fill_parent"
android:layout_height="wrap_content">
android:onClick="re_login"
android:id="@+id/re_login"
android:layout_width="100dp"
android:layout_height="40dp"
android:background="@drawable/re_login"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"/>
android:id="@+id/change_password"
android:layout_width="100dp"
android:layout_height="40dp"
android:background="@drawable/change_password"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"/>
5.3 Android调用WebService的设计
5.3.1 WebService描述
WebService并不是Android的专利,10几年前就已经出现了。
根据W3C的定义,Web Services(Web服务)是一个用于支持网络间不同机器互操作的软件系统,它是一种自包含、自描述和模块化的应用程序,它可以在网络中被描述、发布和调用,可以将它看作是基于网络的、分布式的模块化组件[10]。
Web Services是建立在通用协议的基础之上,如HTTP、SOAP、UDDI、WSDL等,这些协议在操作系统、编程语言和对象模型的选择上没有任何倾向,因此有着很强的生命力[11]。
Web Services的优势在于提供了不同应用程序平台之间的互操作,它使得基于组件的开发和Web相结合的效果达到最佳。它是基于HTTP协议的,调用请求和回应消息都可以穿过防火墙,这样就避免了使用特殊端口进行通信时无法穿越防火墙的问题。
简单的理解:通常我们所说的WebService都是远程的某个服务器对外公开了某种服务,或者理解为对外公开了某个功能或者方法,而我们可以通过编程来调用该服务以获得我们需要的信息。例如:webxml对外公开了[网学网用户上传]归属地查询服务,我们只需要在调用该服务时传入一个手机号段(号码),就能立即获取该号段的归属地信息。
更通俗的理解:通过使用WebService,我们能够像调用本地方法一样去调用远程服务器上的方法。我们并不需要关心远程的那个方法是Java写的,还是PHP或C#写的;我们并不需要关心远程的方法是基于Unix平台,还是Windows平台,也就是说WebService与平台和语言无关。
Web Services是建立在HTTP、SOAP、WSDL等通用协议的基础之上。
SOAP(Simple Object Access Protocol,简单对象访问协议)是一种轻量级的、简单的、基于XML的协议,被设计用于在分布式环境中交换格式化和固化信息的简单协议。也就是说,要进行通信,进行数据访问传输,就必须依赖于一定的协议,而SOAP正是WebService通信中所依赖的一种协议。目前经常使用的SOAP协议有两个版本:SOAP 1.1 和 SOAP 1.2。
WSDL(Web Services Description Language,即Web服务描述语言)是一种用来描述Web服务的XML语言,它描述了Web服务的功能、接口、参数、返回值等,便于用户绑定和调用服务。它以一种和具体语言无关的方式定义了给定Web服务调用和应答的相关操作和消息。
WSDL是我们能够实实在在看到的东西,它是一份xml文档,用于描述某个WebSerivce的方方面面。例如,本系统服务器端提供了对于数据库添加和查询的WebSerivce,我们如何使用这个WebSerivce,调用它需要传入什么参数,它会返回什么值,这一系列的问题都能在WSDL中找到答案。
当后台将服务发布到服务器上后,在浏览器输入下列网址localhost:9080/sgclpt/services/sgptservice?wsdl,即可看到WSDL文档。因为我将本机作为服务器,将服务发布在了本机,所以上面网址的ip处填的是"localhost"。WSDL文档如下图所示5.4所示。
图5.4 WSDL文档
这样,开发者就明确了该如何调用这个WebService了,接下来就可以使用它的服务,实现Android客户端与服务器端的通信。
5.3.2 调用WebService主要代码
我把Android调用Webservice的方法抽象到一个专门的类里,类名叫做"connection",类里只实现了这一个方法,以便于软件在多个不同的窗口运行都可以直接调用这个连接服务器
上一篇:
安卓操作系统下嵌入式图像分析软件开发与移植---毕业论文
下一篇:
试论APP广告在手机中的应用