麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

自定義圓加載進度單點觸控

2019-11-09 14:15:13
字體:
來源:轉載
供稿:網友
//布局文件<?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"    tools:context="com.bw.u.day02dandianchukong.MainActivity">    <com.bw.u.day02dandianchukong.MyView    android:id="@+id/cv"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    />    <Button        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:onClick="start"        android:text="點擊加載"        android:layout_alignParentBottom="true"        android:layout_alignParentLeft="true"        android:layout_alignParentStart="true"        android:id="@+id/button" />    <Button        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:onClick="startJia"        android:text="點擊加載加速"        android:layout_above="@+id/button"        android:layout_alignParentLeft="true"        android:layout_alignParentStart="true"        android:id="@+id/button2" /></RelativeLayout>//代碼部分 
package com.bw.u.day02dandianchukong;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;public class MainActivity extends AppCompatActivity {    int max=360;    int current=0;    MyView cv;    @Override    PRotected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        cv = (MyView) findViewById(R.id.cv);    }    public void start(View view){        current=0;        new Thread(new Runnable() {            public void run() {                while(current<=360){                    current++;                    try {                        Thread.sleep(20);                    } catch (InterruptedException e) {                        e.printStackTrace();                    }                    cv.addrest(max,current);                }            }        }){}.start();    }    //點擊加速    public void startJia(View view){        current+=2;        new Thread(new Runnable() {            public void run() {                while(current<=360){                    current++;                    try {                        Thread.sleep(20);                    } catch (InterruptedException e) {                        e.printStackTrace();                    }                    cv.addrest(max,current);                }            }        }){}.start();    }    }//繼承view 
package com.bw.u.day02dandianchukong;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.RectF;import android.util.AttributeSet;import android.view.MotionEvent;import android.view.View;import android.widget.Toast;public class MyView extends View{    //聲明畫筆    Paint paint;    //聲明第二個畫筆    Paint cpaint;    //聲明進度畫筆    Paint jpaint;    //最大值    int max = 360;    //當前進度    int current;    float textsize = 30;    //創建方法發送線程    public void addrest(int max, int current) {        this.max = max;        this.current = current;        postInvalidate();    }    private float x=202;    private float y=317;    public MyView(Context context) {        this(context,null);    }    public MyView(Context context, AttributeSet attrs) {        this(context, attrs,R.style.APPTheme);    }    public MyView(Context context, AttributeSet attrs, int defStyleAttr) {        super(context, attrs, defStyleAttr);    }    protected void onDraw(Canvas canvas) {        super.onDraw(canvas);        circleview(canvas);    }    public  void circleview(Canvas canvas){        //創建畫圓的畫筆        paint = new Paint();        cpaint = new Paint();        jpaint = new Paint();        int width = getWidth();        //圓的中心        // int center=width/2;        //獲取圓的半徑        int radio = (width - 20) / 2;        paint.setColor(Color.RED);        paint.setStrokeWidth(5);        paint.setStyle(Paint.Style.STROKE);        paint.setAntiAlias(true);        //設置進度條的顏色或者格式        cpaint.setColor(Color.BLUE);        cpaint.setStrokeWidth(3);        cpaint.setStyle(Paint.Style.STROKE);        cpaint.setAntiAlias(true);        //設置字體的顏色或格式        jpaint.setColor(Color.GREEN);        jpaint.setStrokeWidth(2);        jpaint.setTextSize(textsize);        //用畫筆畫出一個圓        canvas.drawCircle(x, y, radio, paint);        //設置進度條的方向或        RectF rectF = new RectF(x - radio, y - radio, x + radio, y + radio);        canvas.drawArc(rectF, 0, 360*current/max, false, cpaint);        //進度條百分比        int perent=(int) ((current*1.0/max*1.0)*100);        float textWidth=paint.measureText(perent+"%");        canvas.drawText(perent+"%",x-textWidth/2,y+textWidth/2,jpaint);    }    public boolean onTouchEvent(MotionEvent event) {        switch (event.getAction()){            case MotionEvent.ACTION_DOWN:                Toast.makeText(getContext(),"點擊圓內",Toast.LENGTH_SHORT).show();            break;            case MotionEvent.ACTION_MOVE:                this.x=event.getX();                this.y=event.getY();                this.invalidate();                break;        }        return true;    }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 福利在线免费视频 | 国产一区在线免费 | 福利在线播放 | 免费久久精品 | 杏美月av| 欧美3p激情一区二区三区猛视频 | 羞羞的网址 | 成人羞羞在线观看网站 | 国产精品美女久久久久久不卡 | 成人免费国产 | 精品免费国产一区二区三区 | 欧美激情性色生活片在线观看 | 免费黄色一级网站 | 成品片a免费直接观看 | 线观看免费完整aaa 一二区成人影院电影网 | 久久综合入口 | 午夜视频你懂的 | 蜜桃成品人免费视频 | 石原莉奈日韩一区二区三区 | 99riav国产在线观看 | 欧美成人视 | 欧洲成人一区 | 国产69精品久久久久久野外 | 国产日本在线播放 | 成人青青草 | 国产精品久久久久久久久久了 | 久久毛片| 国产1区2| 日本一区二区在线看 | 视频国产一区二区 | 亚洲爱爱网站 | 久久国产精品无码网站 | 国产亚洲精品美女久久久 | 激情久久一区二区 | 欧美日韩在线看片 | 亚洲精品永久视频 | 在线观看一区二区三区四区 | 国产小视频在线观看 | 舌头伸进添的我好爽高潮网站 | 国产羞羞视频在线观看免费应用 | 欧美日韩国产成人在线观看 |