重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

android划线,安卓手机上划线怎样设置

android 中如何画一条动态的画一条直线.(即从A到慢慢运动到B点的轨迹,走过后轨迹是一条线)

首先找到这条直线的所有点,然后开启一个线程循环获取点,用Handle发送消息去画线

成都创新互联是一家企业级云计算解决方案提供商,超15年IDC数据中心运营经验。主营GPU显卡服务器,站群服务器,德阳服务器托管,海外高防服务器,大带宽服务器,动态拨号VPS,海外云手机,海外云服务器,海外服务器租用托管等。

@Override

public void run() {

try {

for(int i = 0 ; i myPointList.size(); i++)

{

MyPoint myPoint = myPointList1.get(i);

Message message = Message.obtain();

message.what = 2;

message.obj = myPoint;

mHandler.sendMessage(message);

Thread.sleep(100);

}

} catch (Exception e) {

e.printStackTrace();

}

}

android中如何利用view视图添加一条直线

你好!

步骤1:在你创建的工程中新建一个class文件,随便起个名字叫MyView吧,打开文件会看到:

public

class

MyView

{

}

步骤2:让该类继承

View类,也就是在MyView后面添几个字母,如:

public

class

MyView

extends

View

{

}

步骤3:在上面的这个类中,写一个方法:

public

class

MyView

extends

View

{

protected

void

onDraw(Canvas

canvas)

{

..........

}

}

步骤4:在onDrow方法中写一条语句:

public

class

MyView

extends

View

{

protected

void

onDraw(Canvas

canvas)

{

canvas.drawLine(起点横坐标,起点纵坐标,终点横坐标,终点纵坐标,线的颜色);

}

}

注:看到“drawLine”了吧,这就是在画线。

如有疑问,请追问。

android 如何画一条线

public class MainActivity extends Activity {

private ImageView iv;

private Bitmap baseBitmap;

private Canvas canvas;

private Paint paint;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

this.iv = (ImageView) this.findViewById(R.id.iv);

// 创建一张空白图片

baseBitmap = Bitmap.createBitmap(480, 640, Bitmap.Config.ARGB_8888);

// 创建一张画布

canvas = new Canvas(baseBitmap);

// 画布背景为灰色

canvas.drawColor(Color.GRAY);

// 创建画笔

paint = new Paint();

// 画笔颜色为红色

paint.setColor(Color.RED);

// 宽度5个像素

paint.setStrokeWidth(5);

// 先将灰色背景画上

canvas.drawBitmap(baseBitmap, new Matrix(), paint);

iv.setImageBitmap(baseBitmap);

iv.setOnTouchListener(new OnTouchListener() {

int startX;

int startY;

@Override

public boolean onTouch(View v, MotionEvent event) {

switch (event.getAction()) {

case MotionEvent.ACTION_DOWN:

// 获取手按下时的坐标

startX = (int) event.getX();

startY = (int) event.getY();

break;

case MotionEvent.ACTION_MOVE:

// 获取手移动后的坐标

int stopX = (int) event.getX();

int stopY = (int) event.getY();

// 在开始和结束坐标间画一条线

canvas.drawLine(startX, startY, stopX, stopY, paint);

// 实时更新开始坐标

startX = (int) event.getX();

startY = (int) event.getY();

iv.setImageBitmap(baseBitmap);

break;

}

return true;

}

});

}

public void save(View view) {

try {

File file = new File(Environment.getExternalStorageDirectory(),

System.currentTimeMillis() + ".jpg");

OutputStream stream = new FileOutputStream(file);

baseBitmap.compress(CompressFormat.JPEG, 100, stream);

stream.close();

// 模拟一个广播,通知系统sdcard被挂载

Intent intent = new Intent();

intent.setAction(Intent.ACTION_MEDIA_MOUNTED);

intent.setData(Uri.fromFile(Environment

.getExternalStorageDirectory()));

sendBroadcast(intent);

Toast.makeText(this, "保存图片成功", 0).show();

} catch (Exception e) {

Toast.makeText(this, "保存图片失败", 0).show();

e.printStackTrace();

}

}

}

android 百度地图上怎么画线,画圆

//代码如下

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;// 连线的点

@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);

// 设置在缩放动画过程中也显示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);

}

}

}


标题名称:android划线,安卓手机上划线怎样设置
本文链接:http://cqcxhl.com/article/dsesjoe.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP