public class ZhuanPan2 extends View implements View.OnClickListener{    private Paint mPaint;    private int mwidth;    private int mpidding;    private boolean isstart=false;    private RotateAnimation mRotateAnimation;    private RectF mRectF;    private String[] waitext=new String[]{"苹果","橘子","香蕉","荔枝","榴莲","葡萄"};    private int[] colors=new int[]{Color.parseColor("#8EE5EE"),Color.parseColor("#FFD700"),Color.parseColor("#8EE5EE"),Color.parseColor("#FFD700"),Color.parseColor("#8EE5EE"),Color.parseColor("#FFD700")};    private String neitext="start";    public ZhuanPan2(Context context) {        super(context);    }    public ZhuanPan2(Context context, @Nullable AttributeSet attrs) {        super(context, attrs);        mypiant();        myRotateAnimation();        setOnClickListener(this);    }    public ZhuanPan2(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {        super(context, attrs, defStyleAttr);    }    private void mypiant() {        mPaint=new Paint();        mPaint.setStrokeWidth(3);        mPaint.setAntiAlias(true);        mPaint.setColor(Color.WHITE);        mPaint.setStyle(Paint.Style.STROKE);    }    private void myRotateAnimation() {        mRotateAnimation=new RotateAnimation(0,360, Animation.RELATIVE_TO_SELF,0.5f, Animation.RELATIVE_TO_SELF,0.5f);        mRotateAnimation.setFillAfter(true);        mRotateAnimation.setRepeatCount(-1);    }    @Override    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {        setMeasuredDimension(300,300);        mwidth = getMeasuredWidth();        mpidding=5;        mRectF=new RectF(0,0,mwidth,mwidth);    }    @Override    protected void onDraw(Canvas canvas) {        super.onDraw(canvas);        canvas.drawCircle(mwidth/2,mwidth/2,mwidth/2-mpidding,mPaint);        mPaint.setStyle(Paint.Style.FILL);        inityuan(canvas);        mPaint.setColor(Color.RED);        mPaint.setStyle(Paint.Style.FILL);        canvas.drawCircle(mwidth/2,mwidth/2,50,mPaint);        mPaint.setColor(Color.WHITE);        mPaint.setTextSize(24);        Rect rect=new Rect();        mPaint.getTextBounds(neitext,0,neitext.length(),rect);        int width = rect.width();        int height = rect.height();        canvas.drawText(neitext,mwidth/2-25+25-width/2,mwidth/2+height/2,mPaint);    }    private void inityuan(Canvas canvas) {        for (int i=0;i<6;i++){            mPaint.setColor(colors[i]);            canvas.drawArc(mRectF,(i-1)*60+60,60,true,mPaint);        }        for (int i=0;i<6;i++){            mPaint.setColor(Color.BLACK);            Path path=new Path();            path.addArc(mRectF,(i-1)*60+60,60);            canvas.drawTextOnPath(waitext[i],path,60,60,mPaint);        }    }    @Override    public void onClick(View v) {        if (!isstart){            isstart=true;            mRotateAnimation.setDuration(1000);            mRotateAnimation.setInterpolator(new LinearInterpolator());            startAnimation(mRotateAnimation);        }else {            isstart=false;            clearAnimation();        }    }}

然后写好这个类之后只需在布局文件中设置就行,把宽高设置成自适应否则会出现转盘控件围绕布局公转

<?xml version="1.0" encoding="utf-8"?>           
        

更多相关文章

  1. Android--一段兼容居中和满屏满屏的布局
  2. android recycler添加分割线 点击事件等
  3. Android从下往上(动画)滑出窗口
  4. Android一种欢迎界面全屏显示方法
  5. Android(安卓)PopupWindows使用
  6. AndroidStudio调用摄像头
  7. android-仿iOS弹出框
  8. RecyclerView指定布局管理器
  9. Android文字跑马灯

随机推荐

  1. 启动android默认浏览器
  2. Android客户端GPS定位源码
  3. Android(安卓)7.0,8.0拍照loadXmlMetaData
  4. mtk android sd卡调试
  5. 关于android菜单
  6. 【android】在adapter中获取listview的实
  7. android屏幕保持唤醒
  8. Android(安卓)View的构造方法
  9. Android(安卓)学习系列 - Java 多线程
  10. Android中intent的使用