亲宝软件园·资讯

展开

Android空心圆及层叠效果 Android空心圆及层叠效果实现代码

wyj1369 人气:0
想了解Android空心圆及层叠效果实现代码的相关内容吗,wyj1369在本文为您仔细讲解Android空心圆及层叠效果的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Android,空心圆,层叠,下面大家一起来学习吧。

package com.bwei.test.zidingyiview2;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;


public class MyView extends View {
 private Context mcontext;
 private Paint mpaint;

 public MyView(Context context) {
  super(context);
 }

 public MyView(Context context, AttributeSet attrs) {
  super(context, attrs);
 }

 public MyView(Context context, AttributeSet attrs, int defStyleAttr) {
  super(context, attrs, defStyleAttr);
  this.mcontext = context;
 }

 @Override
 protected void onDraw(Canvas canvas) {
  super.onDraw(canvas);
//  得到屏幕宽高
  float wi = canvas.getWidth() / 2;
  float he = canvas.getHeight() / 2;
//  创建第一个画笔
  Paint pa = new Paint();
//  上色
  pa.setColor(Color.GREEN);
//  显示圆边
  pa.setAntiAlias(true);
//  设置空心圆环
  pa.setStyle(Paint.Style.STROKE);
//  设置圆环宽度
  pa.setStrokeWidth(6);
  Paint pa2 = new Paint();
  pa2.setColor(Color.BLUE);
  pa2.setAntiAlias(true);
  Paint pa3 = new Paint();
  pa3.setColor(Color.BLACK);
  pa3.setAntiAlias(true);
//  画什么圆
  canvas.drawCircle(wi-85, he-85, 80, pa2);
  canvas.drawCircle(wi, he, 100, pa);
  canvas.drawCircle(wi+110, he+110, 120, pa3);
 }
}

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:id="@+id/activity_main"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.bwei.test.zidingyiview2.MainActivity">

 <com.bwei.test.zidingyiview2.MyView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"/>
</RelativeLayout>

加载全部内容

相关教程
猜你喜欢
用户评论