Android模拟打电话程序实现
Android模拟打电话程序实现
首先建一个新项目叫Myphone
1、界面设计很简单
打开main.xml文件编辑添一个编译文本框和一个按钮代码如下:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/phone" />
- <EditText
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:id="@+id/text"
- />
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/button"
- android:text="@string/button"
- />
- </LinearLayout>
代码 :
<?xml version="1.0" encoding="utf-8"?>
XML (Extensible Markup Language) 是一种标记描述语言,不管是语法还是看起来的样子,都相当类似网页所使用的 HTML 标记语言。 XML 被广泛地运用在 Java 程序的设定 中 。 main.xml文件里,第一行是每个 XML 描述档固定的开头内容,用来指示这个文字档 桉是以 XML 格式描述的。
代码 :
<LinearLayout></LinearLayout>" 线性版面配置 "(LinearLayout) 标签,使用了两个「 LinearLayout 」标签,来表示一个界面元件的区块。后头的标签前加上一个「 / 」 符号来表示结束标签。 " 线性版面配置 " 所指的是包含在 「 LinearLayout 」标签中,所有元件的配置方式,是将一个接一个元件由上而下排队排下来的意思。
代码 :
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns 开头的这串叙述,是用来宣告这个 XML 描述档桉的的名称空间 (NameSpace) , 后面接的 URL( 网址 ) ,表示这个描述档桉会参照到 Android 名称空间提供的定义。 所有Android 版面配置档桉的最外层标签中,都必须包含这个属性。
android:layout_width定义宽度,它有fill_parent(填满整个上层元件),wrap_content值,还有自定义一下值以px(是屏幕的像素点)、in(英寸)、mm(毫米)、pt(磅1/72英寸)、dp(一个基于density的抽象单位,如果一个160dpi的屏幕,1dp=1px)、dip(等同于dp)、sp(同dp相似,但是还会根据用户的字体大小偏好来缩放);建议使用sp作为文本的单位,其它用dip!!
android:layout_height定义高度,同上!!
androd:orientation="vertical"版本走向,垂直走!!
android:id="@+id/text"是定义该组件的id
android:text="@string/button"文本是string.xml文件中定义的;
|
评论暂时关闭