最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android自定義View實(shí)現(xiàn)球形動(dòng)態(tài)加速球

 更新時(shí)間:2022年06月29日 16:27:45   作者:360度旋轉(zhuǎn)的貓  
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)球形動(dòng)態(tài)加速球,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android自定義View實(shí)現(xiàn)球形動(dòng)態(tài)加速球的具體代碼,供大家參考,具體內(nèi)容如下

利用貝塞爾曲線畫波浪線封閉黃色矩形,使用PorterDuffXfermode的SRC_ATOP只顯示圓和交疊部分,利用Handler發(fā)送消息模擬進(jìn)度形成動(dòng)態(tài)效果。

代碼:

public class CircleView extends View{
private int width;
private int height;
private Bitmap mBitmap;
private Canvas canvasBit;
private Paint mPaintCircle;
private Paint mPaintline;
private int count;
private Path path;
private int progress;
private int Maxprogress;
public void setMaxprogress(int maxprogress) {
Maxprogress = maxprogress;
? ? }

public void setProgress(int progress) {
this.progress = progress;
? ? }

public int getCount() {
return count;
? ? }

public void setCount(int count) {
this.count = count;//貝塞爾曲線周期循環(huán)
? ? ? ? invalidate();
? ? }

public CircleView(Context context) {
super(context);
? ? }

public CircleView(Context context, AttributeSet attrs) {
super(context, attrs);
mPaintCircle=new Paint();
mPaintCircle.setColor(Color.BLUE);
mPaintCircle.setAntiAlias(true);
mPaintCircle.setStyle(Paint.Style.FILL);

path=new Path();

mPaintline=new Paint();
mPaintline.setAntiAlias(true);
mPaintline.setStyle(Paint.Style.FILL);
mPaintline.setColor(Color.YELLOW);

? ? }

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
width= ?getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec);
height =getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec);
? ? ? ? setMeasuredDimension(width,height);
mBitmap=Bitmap.createBitmap(width,height, Bitmap.Config.ARGB_8888);
canvasBit=new Canvas(mBitmap);//新建bitmap的canvas
mPaintline.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));//顯示圓和交疊的部分
? ? }

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
? ? ? ? canvas.drawColor(Color.BLACK);//背景色
canvasBit.drawCircle(300, 300, 150, mPaintCircle);
path.reset();
path.moveTo(500, progress);//矩形右邊框到圓底部
path.lineTo(500, 500);//右邊框
path.lineTo(count, 500);//下邊框
path.lineTo(count, progress);//左邊框
for (int i=0;i<10;i++){//循環(huán)形成10個(gè)周期的波浪封矩形上邊框
path.rQuadTo(20,5,50,0);
path.rQuadTo(20,-5,50,0);
? ? ? ? }
canvasBit.drawPath(path, mPaintline);
? ? ? ? canvas.drawBitmap(mBitmap,0,0,null);
? ? }
}

//Handler代碼如下

public class MainActivity extends Activity {
private CircleView circleView;
private int count;
private int progress=450;
private static final int START=0x23;
private Handler handler=new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what){
case START:
count++;
progress-=4.5;//圓直徑450,按比例count 1=progress 4.5
if (count<=100){
circleView.setCount(count);
circleView.setProgress(progress);
handler.sendEmptyMessageDelayed(START,20);
? ? ? ? ? ? ? ? ? ? }else {
count=0;
progress=450;
circleView.setProgress(progress);
circleView.setCount(count);
handler.sendEmptyMessageDelayed(START,20);
? ? ? ? ? ? ? ? ? ? }
break;
? ? ? ? ? ? }
? ? ? ? }
? ? };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_main);
circleView= (CircleView) findViewById(R.id.circleview);
handler.sendEmptyMessage(START);
? ? }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

沂水县| 屏东市| 忻城县| 湘乡市| 怀仁县| 大渡口区| 民县| 阿合奇县| 西贡区| 卢湾区| 红安县| 班戈县| SHOW| 承德县| 宝山区| 宜兰市| 禄劝| 白城市| 土默特左旗| 陵川县| 武强县| 大港区| 策勒县| 中卫市| 安西县| 德江县| 昭平县| 枣阳市| 南康市| 平远县| 鱼台县| 泸州市| 都昌县| 杭锦旗| 杭州市| 三门峡市| 临海市| 和林格尔县| 来安县| 尼勒克县| 徐水县|