android 圆圈扩大动画,Android实现3个圆圈的动画

实现了一个类似Windows进度条效果,界面上有三个圆圈,依次有一个圆圈显示白色,其它的圆圈显示蓝色。

画圆圈的View

import Android.content.Context;

import android.graphics.Canvas;

import android.graphics.Color;

import android.graphics.Paint;

import android.graphics.Paint.Style;

import android.util.AttributeSet;

import android.view.View;

/**

* 画圆圈的组件

*

* @author linweidong

* @date 2010-11-05

*/

public class Circle extends View {

public Circle(Context context) {

super(context);

// TODO Auto-generated constructor stub

}

public Circle(Context context, AttributeSet attrs) {

super(context, attrs);

// TODO Auto-generated constructor stub

}

@Override

protected void onDraw(Canvas canvas) {

// TODO Auto-generated method stub

Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

if (StaticString.circleColor == Color.BLUE) {

paint.setColor(Color.BLUE);

} else if (StaticString.circleColor == Color.WHITE) {

paint.setColor(Color.WHITE);

}

paint.setAntiAlias(true);

paint.setStyle(Style.FILL);

canvas.drawCircle(4, 4, 4.0f, paint);  //注意圆心的位置

super.onDraw(canvas);

}

}

在使用圆圈的Activity的XML上加载圆圈组件

android:id="@+id/circle1" android:layout_width="8dip"

android:layout_marginTop="6dip" android:padding="4dip"

android:layout_height="8dip" />

android:id="@+id/circle2" android:layout_width="8dip"

android:layout_marginTop="6dip" android:layout_marginLeft="2dip"

android:padding="4dip" android:layout_height="8dip" />

android:id="@+id/circle3" android:layout_width="8dip"

android:layout_marginTop="6dip" android:layout_marginLeft="2dip"

android:padding="4dip" android:layout_height="8dip" />

android:padding="4dip" 提供半径为4 画圆圈的空间,如果android:layout_width="wrap_content "会占很大空间,因此限定大小

在相关的Activity使用

mCityCircle1 = (View) findViewById(R.id.circle1);

mCityCircle2 = (View) findViewById(R.id.circle2);

mCityCircle3 = (View) findViewById(R.id.circle3);

class CircleThread implements Runnable {

public void run() {

int count = 0;

while (true) {

try {

count++;

if (count % 3 == 0) {

Thread.sleep(100);

StaticString.circleColor = Color.WHITE;

mCityCircle1.postInvalidate();

Thread.sleep(100);

StaticString.circleColor = Color.BLUE;

mCityCircle2.postInvalidate();

Thread.sleep(100);

StaticString.circleColor = Color.BLUE;

mCityCircle3.postInvalidate();

} else if (count % 3 == 1) {

Thread.sleep(100);

StaticString.circleColor = Color.BLUE;

mCityCircle1.postInvalidate();

Thread.sleep(100);

StaticString.circleColor = Color.WHITE;

mCityCircle2.postInvalidate();

Thread.sleep(100);

StaticString.circleColor = Color.BLUE;

mCityCircle3.postInvalidate();

} else {

Thread.sleep(100);

StaticString.circleColor = Color.BLUE;

mCityCircle1.postInvalidate();

Thread.sleep(100);

StaticString.circleColor = Color.BLUE;

mCityCircle2.postInvalidate();

Thread.sleep(100);

StaticString.circleColor = Color.WHITE;

mCityCircle3.postInvalidate();

}

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

 }0b1331709591d260c1c78e86d0c51c18.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值