歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android模擬打電話程序實現

Android模擬打電話程序實現

日期:2017/3/1 10:50:15   编辑:Linux編程

首先建一個新項目叫Myphone

1、界面設計很簡單

打開main.xml文件編輯添一個編譯文本框和一個按鈕代碼如下:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical" >
  6. <TextView
  7. android:layout_width="fill_parent"
  8. android:layout_height="wrap_content"
  9. android:text="@string/phone" />
  10. <EditText
  11. android:layout_width="fill_parent"
  12. android:layout_height="wrap_content"
  13. android:id="@+id/text"
  14. />
  15. <Button
  16. android:layout_width="wrap_content"
  17. android:layout_height="wrap_content"
  18. android:id="@+id/button"
  19. android:text="@string/button"
  20. />
  21. </LinearLayout>
上文件的TextView是一個類似java中的label標簽,相當於html中的input控件,用以輸入的視圖控件!EditText類似於java中的文本框,可編輯的文本框,輸入內容!Button就是一個按鈕!

代碼 :
<?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文件中定義的;

Copyright © Linux教程網 All Rights Reserved