?xml version="1.0" encoding="utf-8"?
創(chuàng)新互聯(lián)建站自2013年創(chuàng)立以來(lái),是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元泊頭做網(wǎng)站,已為上家服務(wù),為泊頭各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:13518219792
shape xmlns:android=""
!-- 圓角 --
corners
android:radius="9dp"
android:topLeftRadius="2dp"
android:topRightRadius="2dp"
android:bottomLeftRadius="2dp"
android:bottomRightRadius="2dp"/!-- 設(shè)置圓角半徑 --
!-- 漸變 --
gradient
android:startColor="@android:color/white"
android:centerColor="@android:color/black"
android:endColor="@android:color/black"
android:useLevel="true"
android:angle="45"
android:type="radial"
android:centerX="0"
android:centerY="0"
android:gradientRadius="90"/
!-- 間隔 --
padding
android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp"/!-- 各方向的間隔 --
!-- 大小 --
size
android:width="50dp"
android:height="50dp"/!-- 寬度和高度 --
!-- 填充 --
solid
android:color="@android:color/white"/!-- 填充的顏色 --
!-- 描邊 --
stroke
android:width="2dp"
android:color="@android:color/black"
android:dashWidth="1dp"
android:dashGap="2dp"/
/shape
//代碼如下
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.baidu.mapapi.BMapManager;
import?com.baidu.mapapi.GeoPoint;
import?com.baidu.mapapi.MapActivity;
import?com.baidu.mapapi.MapController;
import?com.baidu.mapapi.MapView;
import?com.baidu.mapapi.Overlay;
import?com.baidu.mapapi.Projection;
public?class?BaiduMapActivity?extends?MapActivity?{
private?Context?mContext;
private?MapView?mapView;
@Override
protected?boolean?isRouteDisplayed()?{
//?TODO?Auto-generated?method?stub
return?false;
}
private?GeoPoint?gpoint1,?gpoint2,?gpoint3;//?連線的點(diǎn)
@Override
protected?void?onCreate(Bundle?arg0)?{
super.onCreate(arg0);
setContentView(R.layout.baidumap_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);
//?設(shè)置在縮放動(dòng)畫(huà)過(guò)程中也顯示overlay,默認(rèn)為不繪制
mapView.setDrawOverlayWhenZooming(true);
//?RouteLine?routeLine?=
//?(RouteLine)getIntent().getSerializableExtra("routeLine");
//這里畫(huà)點(diǎn)和連接線
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);//設(shè)置一個(gè)起點(diǎn)
}
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();
//?經(jīng)度轉(zhuǎn)像素
projection.toPixels(gpoint1,?p1);
projection.toPixels(gpoint2,?p2);
projection.toPixels(gpoint3,?p3);
//第一個(gè)畫(huà)筆?畫(huà)圓
Paint?fillPaint?=?new?Paint();
fillPaint.setColor(Color.BLUE);
fillPaint.setAntiAlias(true);
fillPaint.setStyle(Style.FILL);
//?將圖畫(huà)到上層
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);
//第二個(gè)畫(huà)筆?畫(huà)線
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);
//畫(huà)出路徑
canvas.drawPath(path,?paint);
}
}
}
能,這是往圖片(圖片轉(zhuǎn)為Bitmap)上寫(xiě)入文字、圖片,你換成畫(huà)圓就是得了。
/**
* 往圖片上寫(xiě)入文字、圖片等內(nèi)容
*/
private void drawNewBitmap(String str) {
Bitmap photo = BitmapFactory.decodeResource(this.getResources(),R.drawable.introduce_first);
int width = photo.getWidth();
int hight = photo.getHeight();
Bitmap bitmap = Bitmap.createBitmap(width, hight, Bitmap.Config.ARGB_8888); // 建立一個(gè)空的BItMap
Canvas canvas = new Canvas(bitmap);// 初始化畫(huà)布繪制的圖像到icon上
Paint photoPaint = new Paint(); // 建立畫(huà)筆
photoPaint.setDither(true); // 獲取跟清晰的圖像采樣
photoPaint.setFilterBitmap(true);// 過(guò)濾一些
Rect src = new Rect(0, 0, photo.getWidth(), photo.getHeight());// 創(chuàng)建一個(gè)指定的新矩形的坐標(biāo)
Rect dst = new Rect(0, 0, width, hight);// 創(chuàng)建一個(gè)指定的新矩形的坐標(biāo)
canvas.drawBitmap(photo, src, dst, photoPaint);// 將photo 縮放或則擴(kuò)大到
// dst使用的填充區(qū)photoPaint
Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);// 設(shè)置畫(huà)筆
textPaint.setTextSize(30.0f);// 字體大小
textPaint.setTypeface(Typeface.DEFAULT_BOLD);// 采用默認(rèn)的寬度
textPaint.setColor(Color.BLACK);// 采用的顏色
canvas.drawText(str, 200, 200, textPaint);// 繪制上去字,開(kāi)始未知x,y采用那只筆繪制
canvas.drawBitmap(BitmapFactory.decodeResource(this.getResources(),R.drawable.ic_launcher), 100, 100, textPaint);
canvas.save(Canvas.ALL_SAVE_FLAG);
canvas.restore();
iv.setBackgroundDrawable(new BitmapDrawable(this.getResources(), bitmap));
saveMyBitmap(bitmap,"test1");
}
主要運(yùn)用SurfaceView來(lái)實(shí)現(xiàn)在屏幕上畫(huà)一個(gè)圓,你可以通過(guò)按方向鍵和觸摸屏幕來(lái)改變圓的位置
代碼:
Activity
package com.view;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 隱藏狀態(tài)欄
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// 把Activity的標(biāo)題去掉
requestWindowFeature(Window.FEATURE_NO_TITLE);
// 設(shè)置布局
this.setContentView(new MySurfaceView(this));
}
}
SurfaceView
package com.view;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
public class MySurfaceView extends SurfaceView implements Runnable, Callback {
private SurfaceHolder mHolder; // 用于控制SurfaceView
private Thread t; // 聲明一條線程
private boolean flag; // 線程運(yùn)行的標(biāo)識(shí),用于控制線程
private Canvas mCanvas; // 聲明一張畫(huà)布
private Paint p; // 聲明一支畫(huà)筆
private int x = 50, y = 50, r = 10; // 圓的坐標(biāo)和半徑
public MySurfaceView(Context context) {
super(context);
mHolder = getHolder(); // 獲得SurfaceHolder對(duì)象
mHolder.addCallback(this); // 為SurfaceView添加狀態(tài)監(jiān)聽(tīng)
p = new Paint(); // 創(chuàng)建一個(gè)畫(huà)筆對(duì)象
p.setColor(Color.WHITE); // 設(shè)置畫(huà)筆的顏色為白色
setFocusable(true); // 設(shè)置焦點(diǎn)
}
/**
* 自定義一個(gè)方法,在畫(huà)布上畫(huà)一個(gè)圓
*/
public void Draw() {
mCanvas = mHolder.lockCanvas(); // 獲得畫(huà)布對(duì)象,開(kāi)始對(duì)畫(huà)布畫(huà)畫(huà)
mCanvas.drawRGB(0, 0, 0); // 把畫(huà)布填充為黑色
mCanvas.drawCircle(x, y, r, p); // 畫(huà)一個(gè)圓
mHolder.unlockCanvasAndPost(mCanvas); // 完成畫(huà)畫(huà),把畫(huà)布顯示在屏幕上
}
/**
* 當(dāng)SurfaceView創(chuàng)建的時(shí)候,調(diào)用此函數(shù)
*/
@Override
public void surfaceCreated(SurfaceHolder holder) {
t = new Thread(this); // 創(chuàng)建一個(gè)線程對(duì)象
flag = true; // 把線程運(yùn)行的標(biāo)識(shí)設(shè)置成true
t.start(); // 啟動(dòng)線程
}
/**
* 當(dāng)SurfaceView的視圖發(fā)生改變的時(shí)候,調(diào)用此函數(shù)
*/
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
}
/**
* 當(dāng)SurfaceView銷毀的時(shí)候,調(diào)用此函數(shù)
*/
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
flag = false; // 把線程運(yùn)行的標(biāo)識(shí)設(shè)置成false
}
/**
* 當(dāng)屏幕被觸摸時(shí)調(diào)用
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
x = (int) event.getX(); // 獲得屏幕被觸摸時(shí)對(duì)應(yīng)的X軸坐標(biāo)
y = (int) event.getY(); // 獲得屏幕被觸摸時(shí)對(duì)應(yīng)的Y軸坐標(biāo)
return true;
}
/**
* 當(dāng)用戶按鍵時(shí)調(diào)用
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_DPAD_UP){ //當(dāng)用戶點(diǎn)擊↑鍵時(shí)
y--; //設(shè)置Y軸坐標(biāo)減1
}
return super.onKeyDown(keyCode, event);
}
@Override
public void run() {
while (flag) {
Draw(); // 調(diào)用自定義畫(huà)畫(huà)方法
try {
Thread.sleep(50); // 讓線程休息50毫秒
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
MySurfaceView首先繼承SurfaceView,然后實(shí)現(xiàn)Runnable和Callback接口
重寫(xiě)了Runnable的run方法和Callback的surfaceCreated(SurfaceHolder holder),surfaceChanged(SurfaceHolder holder, int format, int width,int height),surfaceDestroyed(SurfaceHolder holder)方法,
還實(shí)現(xiàn)了onTouchEvent(MotionEvent event),onKeyDown(int keyCode, KeyEvent event)方法來(lái),詳細(xì)的在代碼里已注釋。
畫(huà)圓應(yīng)該很簡(jiǎn)單,自動(dòng)循環(huán)的話,你就每隔一段時(shí)間刷新一下view
網(wǎng)站標(biāo)題:畫(huà)圓android,畫(huà)圓的方法素描
文章起源:http://jinyejixie.com/article0/dsedpoo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、面包屑導(dǎo)航、App設(shè)計(jì)、微信公眾號(hào)、搜索引擎優(yōu)化、全網(wǎng)營(yíng)銷推廣
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)