❶ 高德地圖,android開發中,怎麼用經緯度來顯示地圖
首先創建工程,並在工程Build Path>Configure Build Path…>libraries 中選擇「Add Externel JARs…」,選定
MapApi.jar,點擊OK,這樣就可以將高德地圖Android API 庫文件引入。然後在工程Build Path>Configure Build
Path…>Order and Export 中將引入的庫文件MapApi.jar 選中,點擊OK,這樣您就可以在您的程序中使用高德地圖API
了。
二、我們在不熟悉的情況下、先盡量多的添加此軟體應用許可權;所以在mainifest中添加如下代碼;插入的位置在
<application的代碼之前。
java代碼
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
三、接著就要在res文件下的layout中添加界面布局了。其代碼如下、你可以完全復制進去。
Java代碼
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<!--添加文本輸入框,查找地址-->
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content" android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="center_horizontal">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="經度"/>
<EditText android:layout_height="fill_parent"
android:layout_width="100px"
android:id="@+id/longitude"/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="緯度"/>
<EditText android:layout_height="fill_parent"
android:layout_width="100px"
android:id="@+id/latitude"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="查找"
android:id="@+id/button"/>
</LinearLayout>
<com.amap.mapapi.map.MapView android:id="@+id/mapView"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:clickable="true"
/>
</LinearLayout>
四、最後就是軟體的主程序部分了、裡面需要的類和方法不多,主要以按鈕的監聽器和地圖的界面實現為主
Java代碼
public void onCreate(Bundle savedInstanceState) {
// this.setMapMode(MAP_MODE_VECTOR);//設置地圖為矢量模式
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setBuiltInZoomControls(true); // 設置啟用內置的縮放控制項
mMapController = mMapView.getController(); // 得到mMapView
// 的控制權,可以用它控制和驅動平移和縮放
point = new GeoPoint((int) (39.982378 * 1E6), (int) (116.304923 * 1E6)); // 用給定的經緯度構造一個GeoPoint,單位是微度(度*
// 1E6)
// 按鈕添加監聽器
button_location = (Button) findViewById(R.id.location);
longitude = (EditText) findViewById(R.id.longitude);
latite = (EditText) findViewById(R.id.latitude);
locationListener = new OnClickListener() {
public void onClick(View e) {
if (e.equals(button_location)) {
// 得到文本輸入框的中經緯 度坐標值
String latStr = longitude.getText().toString();
// 將得到的字元串轉成數值
double lat = Integer.parseInt(latStr);
String lngStr = latite.getText().toString();
double lng = Integer.parseInt(lngStr);
//轉成經緯度坐標
lat=lat*1E6;
lng=lng*1E6;
// 用給定的經緯度構造一個GeoPoint,單位是微度(度*1E6)
point = new GeoPoint((int) (lat), (int) (lng));
mMapController.setCenter(point); // 設置地圖中心點
mMapController.setZoom(12); // 設置地圖zoom 級別
// 添加地圖覆蓋物
// MyLocationOverlay(this, mMapView);
mylocTest.enableMyLocation(); // 判斷是否發現位置提供者
mylocTest.enableCompass(); // 打開指南針
mMapView.getOverlays().add(mylocTest);// 添加定位覆蓋物
}
}
};
// 按鈕添加監聽器
button_location.setOnClickListener(locationListener);
mMapController.setCenter(point); // 設置地圖中心點
mMapController.setZoom(12); // 設置地圖zoom 級別
// 添加地圖覆蓋物
mylocTest = new MyLocationOverlay(this, mMapView);
mylocTest.enableMyLocation(); // 判斷是否發現位置提供者
mylocTest.enableCompass(); // 打開指南針
mMapView.getOverlays().add(mylocTest);// 添加定位覆蓋物
}
//另外一個添加界面覆蓋物的類:
public class MyLocationOverlayProxy extends com.amap.mapapi.map.MyLocationOverlay{
private Location mLocation;
protected final Paint mPaint = new Paint();
protected final Paint mCirclePaint = new Paint();
private Bitmap gps_marker=null;
private Point mMapCoords = new Point();
private final float gps_marker_CENTER_X;
private final float gps_marker_CENTER_Y;
private final LinkedList<Runnable> mRunOnFirstFix = new LinkedList<Runnable>();
public MyLocationOverlayProxy(amap amap, MapView mMapView) {
super(amap, mMapView);
gps_marker = ((BitmapDrawable) amap.getResources().getDrawable(
R.drawable.marker_gpsvalid)).getBitmap();
gps_marker_CENTER_X = gps_marker.getWidth() / 2 - 0.5f;
gps_marker_CENTER_Y= gps_marker.getHeight() / 2 - 0.5f;
}
public boolean runOnFirstFix(final Runnable runnable) {
if (mLocation != null) {
new Thread(runnable).start();
return true;
} else {
mRunOnFirstFix.addLast(runnable);
return false;
}
}
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
mLocation = location;
for(final Runnable runnable : mRunOnFirstFix) {
new Thread(runnable).start();
}
mRunOnFirstFix.clear();
super.onLocationChanged(location);
}
protected void drawMyLocation(Canvas canvas, MapView mapView, final Location mLocation,
GeoPoint point, long time) {
Projection pj=mapView.getProjection();
if (mLocation != null) {
mMapCoords=pj.toPixels(point, null);
final float radius = pj.metersToEquatorPixels(mLocation.getAccuracy());
this.mCirclePaint.setAntiAlias(true);
this.mCirclePaint.setARGB(35, 131, 182, 222);
this.mCirclePaint.setAlpha(50);
this.mCirclePaint.setStyle(Style.FILL);
canvas.drawCircle(mMapCoords.x, mMapCoords.y, radius, this.mCirclePaint);
this.mCirclePaint.setARGB(225, 131, 182, 222);
this.mCirclePaint.setAlpha(150);
this.mCirclePaint.setStyle(Style.STROKE);
canvas.drawCircle(mMapCoords.x, mMapCoords.y, radius, this.mCirclePaint);
canvas.drawBitmap(gps_marker, mMapCoords.x-gps_marker_CENTER_X, mMapCoords.y-gps_marker_CENTER_Y, this.mPaint);
}
}
}
❷ android 怎麼通過js調用手機通訊錄
思路:
1、js調用android的java代碼
2、通過java代碼訪問通訊錄
3、通過java代碼訪問js代碼返回通訊錄信息
代碼:
1、js調用android的java代碼
js代碼:
window.ncp.callOnJs2("click");
android代碼,通過webview打開頁面:
mWebview.getSettings().setJavaScriptEnabled(true);
mWebView.addJavascriptInterface(newJavaScriptInterface(),"ncp");
finalclassJavaScriptInterface{
publicintcallOnJs(){
return1000;
}
publicvoidcallOnJs2(Stringmode){
//TODO
}
}
2、通過java代碼訪問通訊錄
/**得到手機通訊錄聯系人信息**/
privatevoidgetPhoneContacts(){
ContentResolverresolver=mContext.getContentResolver();
//獲取手機聯系人
CursorphoneCursor=resolver.query(Phone.CONTENT_URI,PHONES_PROJECTION,null,null,null);
if(phoneCursor!=null){
while(phoneCursor.moveToNext()){
//得到手機號碼
StringphoneNumber=phoneCursor.getString(PHONES_NUMBER_INDEX);
//當手機號碼為空的或者為空欄位跳過當前循環
if(TextUtils.isEmpty(phoneNumber))
continue;
//得到聯系人名稱
StringcontactName=phoneCursor.getString(PHONES_DISPLAY_NAME_INDEX);
//得到聯系人ID
Longcontactid=phoneCursor.getLong(PHONES_CONTACT_ID_INDEX);
//得到聯系人頭像ID
Longphotoid=phoneCursor.getLong(PHONES_PHOTO_ID_INDEX);
//得到聯系人頭像Bitamp
BitmapcontactPhoto=null;
//photoid大於0表示聯系人有頭像如果沒有給此人設置頭像則給他一個默認的
if(photoid>0){
Uriuri=ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI,contactid);
InputStreaminput=ContactsContract.Contacts.openContactPhotoInputStream(resolver,uri);
contactPhoto=BitmapFactory.decodeStream(input);
}else{
contactPhoto=BitmapFactory.decodeResource(getResources(),R.drawable.contact_photo);
}
mContactsName.add(contactName);
mContactsNumber.add(phoneNumber);
mContactsPhonto.add(contactPhoto);
}
phoneCursor.close();
}
3、通過java代碼訪問js代碼返回通訊錄信息
mWebView.loadUrl("javascript:onSaveCallback()");
❸ Android四大組件是什麼講講你對它們的理解
Android有四大組件:Activity、Service、Broadcast Receiver、Content Provider。
Activity
做一個完整的Android程序,不想用到Activity,真的是比較困難的一件事情,除非是想做綠葉想瘋了。因為Activity是Android程序與用戶交互的窗口,在我看來,從這個層面的視角來看,Android的Activity特像網站的頁面。
Activity,在四大組件中,無疑是最復雜的,這年頭,一樣東西和界面掛上了勾,都簡化不了,想一想,獨立做一個應用有多少時間淪落在了界面上,就能琢磨清楚了。從視覺效果來看,一個Activity占據當前的窗口,響應所有窗口事件,具備有控制項,菜單等界面元素。從內部邏輯來看,Activity需要為了保持各個界面狀態,需要做很多持久化的事情,還需要妥善管理生命周期,和一些轉跳邏輯。對於開發者而言,就需要派生一個Activity的子類,然後埋頭苦幹上述事情。對於Activity的更多細節,先可以參見:reference/android/app/Activity.html。後續,會獻上更為詳盡的剖析。
Service
服務,從最直白的視角來看,就是剝離了界面的Activity,它們在很多Android的概念方面比較接近,都是封裝有一個完整的功能邏輯實現,只不過Service不拋頭露臉,只是默默無聲的做堅實的後盾。
但其實,換個角度來看,Android中的服務,和我們通常說的Windows服務,Web的後台服務又有一些相近,它們通常都是後台長時間運行,接受上層指令,完成相關事務的模塊。用運行模式來看,Activity是跳,從一個跳到一個,呃...,這有點像模態對話框(或者還像web頁面好了...),給一個輸入(抑或沒有...),然後不管不顧的讓它運行,離開時返回輸出(同抑或沒有...)。
而Service不是,它是等,等著上層連接上它,然後產生一段持久而纏綿的通信,這就像一個用了Ajax頁面,看著沒啥變化,偷偷摸摸的和Service不知眉來眼去多少回了。
但和一般的Service還是有所不同,Android的Service和所有四大組件一樣,其進程模型都是可以配置的,調用方和發布方都可以有權利來選擇是把這個組件運行在同一個進程下,還是不同的進程下。這句話,可以拿把指甲刀刻進腦海中去,它凸顯了Android的運行特徵。如果一個 Service,是有期望運行在於調用方不同進程的時候,就需要利用Android提供的RPC機制,為其部署一套進程間通信的策略。
Android的RPC實現,如上圖所示(好吧,也是從SDK中拿來主義的...),無甚稀奇,基於代理模式的一個實現,在調用端和服務端都去生成一個代理類,做一些序列化和反序列化的事情,使得調用端和伺服器端都可以像調用一個本地介面一樣使用RPC介面。
Android中用來做數據序列化的類是Parcel,參見:/reference/android/os/Parcel.html,封裝了序列化的細節,向外提供了足夠對象化的訪問介面,Android號稱實現非常高效。
還有就是AIDL (Android Interface Definition Language) ,一種介面定義的語言,服務的RPC介面,可以用AIDL來描述,這樣,ADT就可以幫助你自動生成一整套的代理模式需要用到的類,都是想起來很乏力寫起來很苦力的那種。更多內容,可以再看看:guide/developing/tools/aidl.html,如果有興致,可以找些其他PRC實現的資料lou幾眼。
關於Service的實現,還強推參看API Demos這個Sample裡面的RemoteService實現。它完整的展示了實現一個Service需要做的事情:那就是定義好需要接受的Intent,提供同步或非同步的介面,在上層綁定了它後,通過這些介面(很多時候都是RPC的...)進行通信。在RPC介面中使用的數據、回調介面對象,如果不是標準的系統實現(系統可序列化的),則需要自定義aidl,所有一切,在這個Sample里都有表達,強薦。
Service從實現角度看,最特別的就是這些RPC的實現了,其他內容,都會接近於Activity的一些實現,也許不再會詳述了。
Broadcast Receiver
在實際應用中,我們常需要等,等待系統抑或其他應用發出一道指令,為自己的應用擦亮明燈指明方向。而這種等待,在很多的平台上,都會需要付出不小的代價。
比如,在Symbian中,你要等待一個來電消息,顯示歸屬地之類的,必須讓自己的應用忍辱負重偷偷摸摸的開機啟動,消隱圖標隱藏任務項,潛伏在後台,監控著相關事件,等待轉瞬即逝的出手機會。這是一件很發指的事情,不但白白耗費了系統資源,還留了個流氓軟體的罵名,這真是賣力不討好的正面典型。
在Android中,充分考慮了廣泛的這類需求,於是就有了Broadcast Receiver這樣的一個組件。每個Broadcast Receiver都可以接收一種或若干種Intent作為觸發事件(有不知道Intent的么,後面會知道了...),當發生這樣事件的時候,系統會負責喚醒或傳遞消息到該Broadcast Receiver,任其處置。在此之前和這以後,Broadcast Receiver是否在運行都變得不重要了,及其綠色環保。
這個實現機制,顯然是基於一種注冊方式的,Broadcast Receiver將其特徵描述並注冊在系統中,根據注冊時機,可以分為兩類,被我冠名為冷熱插拔。所謂冷插拔,就是Broadcast Receiver的相關信息寫在配置文件中(求配置文件詳情?稍安,後續奉上...),系統會負責在相關事件發生的時候及時通知到該Broadcast Receiver,這種模式適合於這樣的場景。某事件方式 -> 通知Broadcast -> 啟動相關處理應用。比如,監聽來電、郵件、簡訊之類的,都隸屬於這種模式。而熱插拔,顧名思義,插拔這樣的事情,都是由應用自己來處理的,通常是在 OnResume事件中通過registerReceiver進行注冊,在OnPause等事件中反注冊,通過這種方式使其能夠在運行期間保持對相關事件的關注。比如,一款優秀的詞典軟體(比如,有道詞典...),可能會有在運行期間關注網路狀況變化的需求,使其可以在有廉價網路的時候優先使用網路查詢詞彙,在其他情況下,首先通過本地詞庫來查詞,從而兼顧腰包和體驗,一舉兩得一石二鳥一箭雙雕(注,真實在有道詞典中有這樣的能力,但不是通過 Broadcast Receiver實現的,僅以為例...)。而這樣的監聽,只需要在其工作狀態下保持就好,不運行的時候,管你是天大的網路變化,與我何干。其模式可以歸結為:啟動應用 -> 監聽事件 -> 發生時進行處理。
除了接受消息的一方有多種模式,發送者也有很重要的選擇權。通常,發送這有兩類,一個就是系統本身,我們稱之為系統Broadcast消息,在reference/android/content/Intent.html 的Standard Broadcast Actions,可以求到相關消息的詳情。除了系統,自定義的應用可以放出Broadcast消息,通過的介面可以是 Context.sendBroadcast,抑或是Context.sendOrderedBroadcast。前者發出的稱為Normal broadcast,所有關注該消息的Receiver,都有機會獲得並進行處理;後者放出的稱作Ordered broadcasts,顧名思義,接受者需要按資排輩,排在後面的只能吃前面吃剩下的,前面的心情不好私吞了,後面的只能喝西北風了。
當Broadcast Receiver接收到相關的消息,它們通常做一些簡單的處理,然後轉化稱為一條Notification,一次振鈴,一次震動,抑或是啟動一個 Activity進行進一步的交互和處理。所以,雖然Broadcast整個邏輯不復雜,卻是足夠有用和好用,它統一了Android的事件廣播模型,讓很多平台都相形見絀了。更多Broadcast Receiver相關內容,參見:/reference/android/content/BroadcastReceiver.html。
Content Provider
Content Provider,聽著就和數據相關,沒錯,這就是Android提供的第三方應用數據的訪問方案。在Android中,對數據的保護是很嚴密的,除了放在SD卡中的數據,一個應用所持有的資料庫、文件、等等內容,都是不允許其他直接訪問的,但有時候,溝通是必要的,不僅對第三方很重要,對應用自己也很重要。
比如,一個聯系人管理的應用。如果不允許第三方的應用對其聯系人資料庫進行增刪該查,整個應用就失去了可擴展力,必將被其他應用拋棄,然後另立門戶,自個玩自個的去了。
Andorid當然不會真的把每個應用都做成一座孤島,它為所有應用都准備了一扇窗,這就是Content Provider。應用想對外提供的數據,可以通過派生ContentProvider類, 封裝成一枚Content Provider,每個Content Provider都用一個uri作為獨立的標識,形如:content://com.xxxxx。所有東西看著像REST的樣子,但實際上,它比REST 更為靈活。和REST類似,uri也可以有兩種類型,一種是帶id的,另一種是列
表的,但實現者不需要按照這個模式來做,給你id的uri你也可以返回列表類型的數據,只要調用者明白,就無妨,不用苛求所謂的REST。
另外,Content Provider不和REST一樣只有uri可用,還可以接受Projection,Selection,OrderBy等參數,這樣,就可以像資料庫那樣進行投影,選擇和排序。查詢到的結果,以Cursor(參見:reference/android/database/Cursor.html )的形式進行返回,調用者可以移動Cursor來訪問各列的數據。
Content Provider屏蔽了內部數據的存儲細節,向外提供了上述統一的介面模型,這樣的抽象層次,大大簡化了上層應用的書寫,也對數據的整合提供了更方便的途徑。Content Provider內部,常用資料庫來實現,Android提供了強大的Sqlite支持,但很多時候,你也可以封裝文件或其他混合的數據。
在Android中,ContentResolver是用來發起Content Provider的定位和訪問的。不過它僅提供了同步訪問的Content Provider的介面。但通常,Content Provider需要訪問的可能是資料庫等大數據源,效率上不足夠快,會導致調用線程的擁塞。因此Android提供了一個AsyncQueryHandler(參見:reference/android/content/AsyncQueryHandler.html),幫助進行非同步訪問Content Provider。
在各大組件中,Service和Content Provider都是那種需要持續訪問的。Service如果是一個耗時的場景,往往會提供非同步訪問的介面,而Content Provider不論效率如何,都提供的是約定的同步訪問介面。我想這遵循的就是場景導向設計的原則,因為Content Provider僅是提供數據訪問的,它不能確信具體的使用場景如何,會怎樣使用它的數據;而相比之下,Service包含的邏輯更復雜更完整,可以抉擇大部分時候使用某介面的場景,從而確定最貼切的介面是同步還是非同步,簡化了上層調用的邏輯。
❹ 求助一個Android 文件選擇器的源碼(用於上傳文件時選擇並...
打開文件選擇器:
private void showFileChooser() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try {
startActivityForResult( Intent.createChooser(intent, "Select a File to Upload"), FILE_SELECT_CODE);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, "Please install a File Manager.", Toast.LENGTH_SHORT).show();
}
}
選擇結果:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FILE_SELECT_CODE:
if (resultCode == RESULT_OK) {
// Get the Uri of the selected file
Uri uri = data.getData();
String path = FileUtils.getPath(this, uri);
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
FileUtils文件
public class FileUtils {
public static String getPath(Context context, Uri uri) {
if ("content".equalsIgnoreCase(uri.getScheme())) {
String[] projection = { "_data" };
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(uri, projection,null, null, null);
int column_index = cursor.getColumnIndexOrThrow("_data");
if (cursor.moveToFirst()) {
return cursor.getString(column_index);
}
} catch (Exception e) {
// Eat it
}
}
else if ("file".equalsIgnoreCase(uri.getScheme())) {
return uri.getPath();
}
return null;
}
}
❺ android手機地圖畫移動軌跡的代碼
package com.life.hua.activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.Point;
import android.os.Bundle;
import com..mapapi.BMapManager;
import com..mapapi.GeoPoint;
import com..mapapi.MapActivity;
import com..mapapi.MapController;
import com..mapapi.MapView;
import com..mapapi.Overlay;
import com..mapapi.Projection;
import com.life.hua.activity.BaseApplication;
import com.life.hua.activity.R;
public class BaiMapActivity extends MapActivity {
private Context mContext;
private MapView mapView;
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
private GeoPoint gpoint1, gpoint2, gpoint3;// 連線的點
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.map_layout);
BaseApplication baseApp = (BaseApplication) this.getApplication();
if (baseApp.mBMapManage == null) {
baseApp.mBMapManage = new BMapManager(mContext);
baseApp.mBMapManage.init(baseApp.mStrKey,
new BaseApplication.MyGeneralListener());
}
baseApp.mBMapManage.start();
super.initMapActivity(baseApp.mBMapManage);// 初始化map sdk
mapView = (MapView) findViewById(R.id.bmapView);
mapView.setBuiltInZoomControls(true);
// 設置在縮放動畫過程中也顯示overlay,默認為不繪制
mapView.setDrawOverlayWhenZooming(true);
// RouteLine routeLine =
// (RouteLine)getIntent().getSerializableExtra("routeLine");
//這里畫點和連接線
MyOverlay myOverlay = new MyOverlay();
mapView.getOverlays().add(myOverlay);
MapController mapController = mapView.getController();
mapController.zoomIn();
gpoint1 = new GeoPoint((int) (2259316 * 10),
(int) (11396279 * 10));
gpoint2 = new GeoPoint((int) (2259245 * 10),
(int) (11396226 * 10));
gpoint3 = new GeoPoint((int) (2259121 * 10),
(int) (11396066 * 10));
mapController.animateTo(gpoint1);//設置一個起點
}
class MyOverlay extends Overlay {
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
super.draw(canvas, mapView, shadow);
Projection projection = mapView.getProjection();
Point p1 = new Point();
Point p2 = new Point();
Point p3 = new Point();
// 經度轉像素
projection.toPixels(gpoint1, p1);
projection.toPixels(gpoint2, p2);
projection.toPixels(gpoint3, p3);
//第一個畫筆 畫圓
Paint fillPaint = new Paint();
fillPaint.setColor(Color.BLUE);
fillPaint.setAntiAlias(true);
fillPaint.setStyle(Style.FILL);
// 將圖畫到上層
canvas.drawCircle(p1.x, p1.y, 5.0f, fillPaint);
canvas.drawCircle(p2.x, p2.y, 5.0f, fillPaint);
canvas.drawCircle(p3.x, p3.y, 5.0f, fillPaint);
//第二個畫筆 畫線
Paint paint = new Paint();
paint.setColor(Color.BLUE);
paint.setDither(true);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setStrokeWidth(4);
//連接
Path path = new Path();
path.moveTo(p1.x, p1.y);
path.lineTo(p2.x, p2.y);
path.lineTo(p3.x, p3.y);
//畫出路徑
canvas.drawPath(path, paint);
}
}
}