画圆android,画圆的方法素描
android 里用shape画圆,怎么填充颜色
?xml version="1.0" encoding="utf-8"?
创新互联建站自2013年创立以来,是专业互联网技术服务公司,拥有项目网站设计、网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元泊头做网站,已为上家服务,为泊头各地企业和个人服务,联系电话:13518219792
shape xmlns:android=""
!-- 圆角 --
corners
android:radius="9dp"
android:topLeftRadius="2dp"
android:topRightRadius="2dp"
android:bottomLeftRadius="2dp"
android:bottomRightRadius="2dp"/!-- 设置圆角半径 --
!-- 渐变 --
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
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 能在bitmap上绘制圆吗
能,这是往图片(图片转为Bitmap)上写入文字、图片,你换成画圆就是得了。
/**
* 往图片上写入文字、图片等内容
*/
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); // 建立一个空的BItMap
Canvas canvas = new Canvas(bitmap);// 初始化画布绘制的图像到icon上
Paint photoPaint = new Paint(); // 建立画笔
photoPaint.setDither(true); // 获取跟清晰的图像采样
photoPaint.setFilterBitmap(true);// 过滤一些
Rect src = new Rect(0, 0, photo.getWidth(), photo.getHeight());// 创建一个指定的新矩形的坐标
Rect dst = new Rect(0, 0, width, hight);// 创建一个指定的新矩形的坐标
canvas.drawBitmap(photo, src, dst, photoPaint);// 将photo 缩放或则扩大到
// dst使用的填充区photoPaint
Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);// 设置画笔
textPaint.setTextSize(30.0f);// 字体大小
textPaint.setTypeface(Typeface.DEFAULT_BOLD);// 采用默认的宽度
textPaint.setColor(Color.BLACK);// 采用的颜色
canvas.drawText(str, 200, 200, textPaint);// 绘制上去字,开始未知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");
}
android如何在屏幕点击位置画一个小圆
主要运用SurfaceView来实现在屏幕上画一个圆,你可以通过按方向键和触摸屏幕来改变圆的位置
代码:
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);
// 隐藏状态栏
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// 把Activity的标题去掉
requestWindowFeature(Window.FEATURE_NO_TITLE);
// 设置布局
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; // 线程运行的标识,用于控制线程
private Canvas mCanvas; // 声明一张画布
private Paint p; // 声明一支画笔
private int x = 50, y = 50, r = 10; // 圆的坐标和半径
public MySurfaceView(Context context) {
super(context);
mHolder = getHolder(); // 获得SurfaceHolder对象
mHolder.addCallback(this); // 为SurfaceView添加状态监听
p = new Paint(); // 创建一个画笔对象
p.setColor(Color.WHITE); // 设置画笔的颜色为白色
setFocusable(true); // 设置焦点
}
/**
* 自定义一个方法,在画布上画一个圆
*/
public void Draw() {
mCanvas = mHolder.lockCanvas(); // 获得画布对象,开始对画布画画
mCanvas.drawRGB(0, 0, 0); // 把画布填充为黑色
mCanvas.drawCircle(x, y, r, p); // 画一个圆
mHolder.unlockCanvasAndPost(mCanvas); // 完成画画,把画布显示在屏幕上
}
/**
* 当SurfaceView创建的时候,调用此函数
*/
@Override
public void surfaceCreated(SurfaceHolder holder) {
t = new Thread(this); // 创建一个线程对象
flag = true; // 把线程运行的标识设置成true
t.start(); // 启动线程
}
/**
* 当SurfaceView的视图发生改变的时候,调用此函数
*/
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
}
/**
* 当SurfaceView销毁的时候,调用此函数
*/
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
flag = false; // 把线程运行的标识设置成false
}
/**
* 当屏幕被触摸时调用
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
x = (int) event.getX(); // 获得屏幕被触摸时对应的X轴坐标
y = (int) event.getY(); // 获得屏幕被触摸时对应的Y轴坐标
return true;
}
/**
* 当用户按键时调用
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_DPAD_UP){ //当用户点击↑键时
y--; //设置Y轴坐标减1
}
return super.onKeyDown(keyCode, event);
}
@Override
public void run() {
while (flag) {
Draw(); // 调用自定义画画方法
try {
Thread.sleep(50); // 让线程休息50毫秒
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
MySurfaceView首先继承SurfaceView,然后实现Runnable和Callback接口
重写了Runnable的run方法和Callback的surfaceCreated(SurfaceHolder holder),surfaceChanged(SurfaceHolder holder, int format, int width,int height),surfaceDestroyed(SurfaceHolder holder)方法,
还实现了onTouchEvent(MotionEvent event),onKeyDown(int keyCode, KeyEvent event)方法来,详细的在代码里已注释。
Android开发,怎样做一个画圆圈的动画效果
画圆应该很简单,自动循环的话,你就每隔一段时间刷新一下view
分享题目:画圆android,画圆的方法素描
链接URL:http://azwzsj.com/article/dsedpoo.html