Android 基礎視訊學習筆記 1 (完結)
綜述:
1 1G-4G的介紹:(瞭解)
1G 大哥大
2G 小靈通 gsm 發簡訊 wap.baidu.com
3G 沃 7.2M
4G :lte 100M/s
5G : 華為 6億美金 10G/s 小公司賣產品大公司賣版權(標準)
2 Android 作業系統的介紹(瞭解)
最初用於數碼相機。Android作業系統在T-Mobile G1手機上首發。
3 Android 系統版本介紹(瞭解)
4 Android 系統構成(掌握)
【1】linux
【2】函式庫存 由C或者C++寫的
【3】Application frameWork 應用的框架層
【4】最上層 應用層
5 jvm與dvm介紹(瞭解)
jvm=>.java->.class->.jar => jdk javac 基於棧的架構
dalvik vm=>.java->.class->.dex->.odex=> sdk dex 基於暫存器的架構
區別:
【1】.dvm把所有的.class檔案變成一個dex檔案
【2】.基於架構的不同
【3】. 為什麼谷歌自己研發dvm => 由於版權的原因
ART模式提升了速度,但是增大了儲存空間的佔用,安裝程式時增長了時間進行預編譯。
6 開發環境的搭建(掌握)
eclipse => ibm用java語言開發的
SDk =>docs文件 sources原始碼 platforms版本檔案存放 .android建立模擬器需要的檔案 temp臨時檔案 platform-tools工具
7 sdkManager介紹
dx.bat 把所有.class檔案變成了一個dex檔案
aapt Android應用打包工具
adb Android除錯橋
doc : 目錄存文件
source:原始碼
platform:開發的平臺
intel : 生產cpu 主要針對pc機或者筆記本
arm : Advanced RISC Machines的縮寫 ,生成標準
===================================================================================
如何進行真機除錯
如果你的手機是雜牌 可以安裝 豌豆莢 360手機助手 金山手機助手 91手機助手等等
如果你的手機驅動能在官網下到 直接下載安裝就可以了
===================================================================================
8 模擬器的簡介及建立
Android 版本對應api級別
2.3 ~~~ 10
3.0 ~~~ 11
4.0 ~~~ 14
4.1.2~~~16
4.4 ~~~ 19
4.4w~~~ 20
5.0 ~~~ 21
Android 常見解析度 =>關乎美工切圖
320*480
480*800
1280*720
ROM :只讀儲存器 相當於電腦的一塊微小的硬碟 斷電後資料不丟失
RAM : 相當於電腦的記憶體條 斷電資料丟失
==============================================================================
2016/11/4 20:00-23:00 完成 模擬器建立 嘗試基本功能 ***休息***
==============================================================================
9 DDMS透檢視介紹
全稱:除錯監控服務工具(Dalvik Debug Monitor Service)
File Explorer 手機檔案 Data->data 檔案包括了系統中安裝的各類應用檔案
Emulator Control 可以模擬簡訊和電話,訊號和位置資訊,漫遊或者未註冊欠費等等狀態。
10 Android-helloworld
Pakeage Name一般使用自己公司的名稱
11 Android工程目錄結構
【1】src 存原始碼的
【2】gen自動生成的檔案。勿動。裡面的R檔案非常重要。R檔案上可以找到所有res檔案中的資源名字。
【3】Android + 版本號 =>開發環境
【4】Android Dependencies 類包
【5】assets 資產目錄 在此檔案中放入圖片在R檔案中是不會被引用的
【6】bin:apk檔案
【7】libs 額外jar包
【8】res資原始檔 drawable 圖片資源
【9】layout 佈局資源
【10】values =>Strings.xml 字串
【11】AndroidManifest.xml 清單檔案=>@相當於R檔案 “@drawable/ic_launcher”表示在R檔案中的drawable下的ic_launcher
Android中的四大元件(Activity broadCastReceiver service ContentProvider)都需要在清單檔案裡配置
12 Android打包流程(瞭解)
編譯-->class->dex檔案 ---打包(aapt)生成一個apk檔案-->adb-->device(瞭解)
13 ADB指令練習(掌握)
【1】kill-server 殺死adb服務
【2】start 啟動
【3】adb install xxxx.apk時出現adb server is out of date.killing的解決辦法(來源於百度經驗)
=>出錯的原因是adb的埠被其他程式的程序佔領了,所以要做的就是找到並kill該程序,
在cmd中執行adb nodaemon server,檢視adb的埠號是多少,一般情況下是5037(why?應該軟體使用的埠號是固定的)
再執行netstat -ano | findstr "5037" :這裡稍微解釋一下,顯示的從左到右的意思分別是,連線型別(TCP)、本地地址和埠、
外部地址和埠、連線狀態、程序的PID號。這裡有兩個程序佔據著5037埠,其中一個佔據的是本地的5037埠,另外一個佔據的是
外部的5037埠,要幹掉的當然就是那個本地的PID為240的埠。CTRL+ALT+DEL喚出工作管理員。點選程序,現在要找的
是PID為240的程序。有時候可能會發現工作管理員裡沒有程序PID的資訊顯示,這時候只要點選工作管理員的檢視-->選擇列,
如下圖,然後把PID勾選上即可。這時候再次檢視當前程序的PID,把PID為240的程序kill掉。
【4】adb uninstall + 應用的包名 快速解除安裝一個安卓應用
【5】adb shell 進入手機終端(進入後操作類似linux)
【6】adb pull test.txt 把一個檔案從終端拉出來 例:adb pull /dev/1.txt
【7】adb push test.txt把一個檔案從終端轉移到電腦上 例:adb push 1.txt /dev/
================================================================================
2016/11/5 20:00-22:51 跟視訊完成操作,瞭解一些基本功能,感覺到了學過linux操作的好處 ***休息***
14 電話撥號器案例(掌握) 意圖物件 Intent
【1】畫UI
【2】根據UI寫對應的業務邏輯 在mainActivity裡面寫 在onCreate方法裡面寫邏輯
【3】給按鈕設定一個點選事件
【4】自己定義一個類去實現方法需要的引數型別
private class MyClickListener implements OnClickListener{
//Called when a view has been Clicked.當按鈕被點選的時候呼叫
@Override
public void onClick(View v) {
//【4】獲取edittext 文字內容
String number = et_number.getText().toString().trim();
if("".equals(number)){
/**
* context 上下文
* Toast.LENGTH_LONG可以用1來表示。short可以用0來表示
*/
Toast.makeText(MainActivity.this, "number不能為空", Toast.LENGTH_LONG).show();
return;
}
//System.out.println("按鈕被點選了"+ number);
//【5】進行撥打電話 意圖Intent
Intent intent = new Intent();//建立一個意圖物件
//【5.1】設定動作
intent.setAction(Intent.ACTION_CALL);
//【5.2】設定要撥打的資料
/**
* uri:同一資源標示符 自己定義的路徑 想什麼就代表什麼
* url:統一資源定位符 www.baidu.com
*/
intent.setData(Uri.parse("tel:"+number));
//【6】開啟意圖
startActivity(intent);
}
}
【5】一定記得加上撥打電話的許可權
<uses-permission android:name="android.permission.CALL_PHONE"/>
真機除錯的時候,如果Android系統版本高於模擬器版本,logcat顯示就不正常。最新的SDK執行的時候會出現
Would you like ADT to automatically monitor logcat output for messages from applications in the workspace.=>選擇Yes
樂視2手機調出開發者模式需要在系統中找到版本號位置連續按七下即可進入開發者模式
SDK版本高,ADT版本低時會在eclipse中顯示不出螢幕,只需要將eclipse上的Android version改為適合的就可以了。我在樂二上使用的是19(4.4)版本。
如果修改中文名導致R檔案亂碼報錯。只需右鍵選擇open with Text Editor .然後左上選單選擇Edit ->set Encoding ->other UTF-8
should use @string/resource 警告:Android建議引用全域性變數,res/values/strings.xml檔案中引用<string name="你要改動的變數的引用名">變數名</string>
例如:
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/AllName"
android:textSize="22sp" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/editText1"
android:text="@string/Message" />
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">helloworld</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="AllName">手機撥號器</string>
<string name="Message">撥號</string>
</resources>
關聯原始碼【1】Open Declaration =>F3 開啟宣告
【2】Attach Source
【3】選擇External location =>External Folder
【4】選擇SDK檔案中的source中對應的Android版本。這裡我選擇的是19。按下OK。
Open type hierarchy=>F4 開啟類層級檢視
==================================================================================
2016/11/6 20:00-23:21 瞭解到瞭如何檢視文件,如何分清繼承關係,踩了幾個坑 ***休息***
學習進度稍慢,考慮是否放下headfirst java,直接看視訊先學Android,每次的選擇都是意志力的消耗,慎之。
==================================================================================
按撥打電話時電話撥號器停止執行:requires android.permission.CALL_PHONE 撥打電話的操作許可權
res=>AndroidMainfest.xml=>permissions=>Add=>Uses Permission=>Name:android.permission.CALL_PHONE
ActivityManager: Warning: Activity not started, its current task has been brought to the front 解決辦法:重啟程式
15 按鈕的四種點選事件(掌握)
【1】定義了一內部類去實現按鈕事件
【2】通過匿名內部類去實現
抽取類:Shift+alt+m
【3】讓當前類實現OnClickListener 介面型別(用於佈局裡面有很多按鈕需要被點選的時候)
【4】在按鈕的佈局上加上一個onClick屬性 在Activity裡面定義一個方法 方法名和屬性名相同(適合自己做一些Demo)
設定一個接收引數View v
16 Android中常用佈局(掌握線性和相對)
android中所有控制元件第一個字母大寫
【1】線性佈局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/action_settings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="請輸入電話號碼"
android:textSize="19sp"
android:layout_marginLeft="10dp"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="請輸入電話號碼"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="撥打"
/>
</LinearLayout>
【2】相對佈局
<RelativeLayout 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" >
<TextView
android:id="@+id/tv_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="撥打此電話"
android:textSize="20sp"
android:layout_margin="10dp"
/>
<EditText
android:id="@+id/tv_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="請輸入電話號碼"
android:layout_below="@+id/tv_number"/>
<Button
android:id="@+id/tv_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="撥打"
android:layout_below="@+id/tv_text"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="撥打2"
android:layout_toRightOf="@+id/tv_button"
android:layout_below="@+id/tv_text"
/>
</RelativeLayout>
【3】幀佈局(播放器中間暫停的控制元件)
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="well"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="暫停"
/>
</FrameLayout>
【4】表格佈局
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="well"
android:layout_marginRight="50dp"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="暫停"
/>
</TableRow>
</TableLayout>
wrap_content 中輸入文字增多框條會向右拉伸,而match_parent則是文字向上堆疊
【5】絕對佈局
is deprecated
QQ鬥地主中的三個頭像
17 Android中單位介紹
padding 內邊距 margin 外間距 避免使用px(在不同屏手機間相同的px所表現的出的效果不同)
dp會根據螢幕解析度自動計算 文字用sp尺寸,非文字用dp尺寸,細線條用px.
==================================================================================
2016/11/7 8:00-14:34 花了三天才斷斷續續看完一天的教程,感覺還是應該多思考。
==================================================================================