├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── example │ │ └── view │ │ └── myview │ │ ├── MainActivity.java │ │ ├── MyView1Activity.java │ │ └── view │ │ ├── DownProgressView.java │ │ └── MyView1.java │ └── res │ ├── drawable-xxhdpi │ ├── btn_down_pause.png │ └── btn_vedio_restart.png │ ├── drawable-xxxhdpi │ ├── btn_down_pause.png │ └── btn_vedio_restart.png │ ├── layout │ ├── activity_main.xml │ └── activity_my_view1.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ ├── btn_down_pause.png │ ├── btn_vedio_restart.png │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gif └── ios_progress.gif ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DownProgressView 2 | Android自定义view之仿ios-appstore下载进度按钮可设置大小,高度,颜色,各状态图片类型! 3 | #仿IOS -appstore之下载进度按钮 4 | 5 | ###先上效果 6 | 程序员不懂设计,大家可以自己配色换图(凑合看看) 7 | 8 | ![效果](https://github.com/wzgiceman/DownProgressView/blob/master/gif/ios_progress.gif) 9 | 10 | ###使用 11 | ```java 12 | setListner(StateProgressListner listner)设置回调监听 13 | setmProgress(int mProgress)设置下载进度 14 | setmFirstColor(int mFirstColor)设置进度圆环的颜色 15 | setmSecondColor(int mSecondColor)设置第一个圆环的颜色 16 | setmCircleWidth(int mCircleWidth)设置加载环的宽度 17 | void setSrcStorp(int srcStorp)设置停止状态图片 18 | setSrcStart(int srcStart)设置开始状态图片资源 19 | void onDestory() 销毁处理 20 | ``` 21 | 22 | ##思路 23 | * 画出一个空的大圆环 24 | * 然后画出进度的弧度 25 | * 监听`touch`事件控制画出暂停和开始的`bitmap` 26 | * 自定义监听返回按钮的状态 27 | 28 | ###初始化工作 29 | ```java 30 | // 第一圈的颜色 31 | private int mFirstColor; 32 | // 第二圈的颜色 33 | private int mSecondColor; 34 | // 圈的宽度 35 | private int mCircleWidth; 36 | // 画笔 37 | private Paint mPaint; 38 | // 当前进度 39 | private int mProgress; 40 | // 圆环中心点 41 | private int centre; 42 | // 状态图片 43 | private Bitmap bitmap; 44 | // 开始状态图片 45 | private int srcStart; 46 | // 暂停状态图片 47 | private int srcStorp; 48 | // 0开始状态;1暂停;2完成 49 | private int state; 50 | // 回调接口 51 | private StateProgressListner listner; 52 | ``` 53 | 54 | 55 | ###画圆 56 | ```java 57 | centre = getWidth() / 2; // 获取圆心的x坐标 58 | int radius = centre - mCircleWidth;// 半径 59 | mPaint.setStrokeWidth(mCircleWidth); // 设置圆环的宽度 60 | mPaint.setAntiAlias(true); // 消除锯齿 61 | mPaint.setStyle(Paint.Style.STROKE); // 设置空心 62 | // 用于定义的圆弧的形状和大小的界限 63 | RectF oval = new RectF(centre - radius, centre - radius, centre + radius, centre + radius); 64 | mPaint.setColor(mFirstColor); // 设置圆环的颜色 65 | canvas.drawCircle(centre, centre, radius, mPaint); // 画出圆环 66 | ``` 67 | 68 | ###画出经度的弧度 69 | 70 | ```java 71 | mPaint.setColor(mSecondColor); // 设置圆环的颜色 72 | mPaint.setStrokeCap(Paint.Cap.ROUND);//两边带圆弧 73 | canvas.drawArc(oval, -90, mProgress, false, mPaint); // 根据进度画圆弧 74 | ``` 75 | 76 | 77 | ###监听`touch`事件 78 | 79 | **1**.监听MotionEvent事件 80 | ```java 81 | @Override 82 | public boolean onTouchEvent(MotionEvent event) { 83 | if (event.getAction() == MotionEvent.ACTION_UP) { 84 | // 判断当前状态 85 | if (state == 0) { 86 | stop(); 87 | } else if (state == 1) { 88 | start(); 89 | } 90 | } 91 | return true; 92 | } 93 | ``` 94 | **2**.绘制开始和暂停状态图片 95 | ```java 96 | /** 97 | * 画出当前的状态图标 98 | * 99 | * @param canvas 100 | */ 101 | private void drawBitmap(Canvas canvas) { 102 | if (bitmap != null) bitmap.recycle(); 103 | bitmap = BitmapFactory.decodeResource(getResources(), state == 0 ? srcStart : srcStorp); 104 | if (bitmap != null) { 105 | int with = bitmap.getWidth(); 106 | int height = bitmap.getHeight(); 107 | canvas.drawBitmap(bitmap, centre - with / 2, centre - height / 2, mPaint); 108 | } 109 | } 110 | ``` 111 | 112 | ##自定义回调接口 113 | **1**创建回调类 114 | ```java 115 | /** 116 | * 自定义监听器 117 | */ 118 | public interface StateProgressListner { 119 | /** 120 | * 开始 121 | */ 122 | void onstart(); 123 | 124 | /** 125 | * 暂停 126 | */ 127 | void onstop(); 128 | 129 | /** 130 | * 结束 131 | */ 132 | void onfinish(); 133 | } 134 | ``` 135 | **2**触发回调事件 136 | 137 | ```java 138 | /** 139 | * 停止 140 | */ 141 | private void stop() { 142 | state = 1; 143 | if (listner != null) { 144 | listner.onstart(); 145 | } 146 | invalidate(); 147 | } 148 | 149 | /** 150 | * 开始 151 | */ 152 | private void start() { 153 | state = 0; 154 | if (listner != null) { 155 | listner.onstop(); 156 | } 157 | invalidate(); 158 | } 159 | 160 | public int getmProgress() { 161 | return mProgress; 162 | } 163 | 164 | /** 165 | * 更新进度条 166 | * 167 | * @param mProgress 168 | */ 169 | public void setmProgress(int mProgress) { 170 | this.mProgress = mProgress; 171 | if (mProgress == 360 && listner != null) { 172 | listner.onfinish(); 173 | } 174 | invalidate(); 175 | } 176 | ``` 177 | 178 | ##主线程中控制状态 179 | 这里我并没有真正的下载,用hander模拟下载进度变化 180 | ```java 181 | public class MyView1Activity extends AppCompatActivity implements DownProgressView.StateProgressListner { 182 | @BindView(R.id.view1) 183 | DownProgressView view1; 184 | int progress; 185 | 186 | @Override 187 | protected void onCreate(Bundle savedInstanceState) { 188 | super.onCreate(savedInstanceState); 189 | setContentView(R.layout.activity_my_view1); 190 | ButterKnife.bind(this); 191 | view1.setListner(this); 192 | } 193 | 194 | 195 | Handler handler = new Handler() { 196 | @Override 197 | public void handleMessage(Message msg) { 198 | super.handleMessage(msg); 199 | view1.setmProgress(++progress); 200 | handler.sendEmptyMessageDelayed(1, 20); 201 | } 202 | 203 | }; 204 | 205 | @Override 206 | public void onstart() { 207 | handler.sendEmptyMessage(1); 208 | } 209 | 210 | @Override 211 | public void onstop() { 212 | handler.removeMessages(1); 213 | } 214 | 215 | @Override 216 | public void onfinish() { 217 | progress = 0; 218 | Toast.makeText(this, "下载完成了!继续开始", Toast.LENGTH_SHORT).show(); 219 | } 220 | 221 | @Override 222 | protected void onDestroy() { 223 | super.onDestroy(); 224 | handler.removeMessages(1); 225 | view1.onDestory(); 226 | } 227 | } 228 | ``` 229 | 230 | 231 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.3" 6 | 7 | defaultConfig { 8 | applicationId "com.example.view.myview" 9 | minSdkVersion 16 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | buildscript { 23 | repositories { 24 | mavenCentral() 25 | } 26 | dependencies { 27 | classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' 28 | } 29 | } 30 | 31 | apply plugin: 'com.neenbedankt.android-apt' 32 | 33 | dependencies { 34 | compile fileTree(include: ['*.jar'], dir: 'libs') 35 | testCompile 'junit:junit:4.12' 36 | compile 'com.android.support:appcompat-v7:23.4.0' 37 | compile 'com.jakewharton:butterknife:8.0.1' 38 | apt 'com.jakewharton:butterknife-compiler:8.0.1' 39 | } 40 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\Android+tool\sdk\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/view/myview/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.view.myview; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.widget.Button; 7 | 8 | import butterknife.BindView; 9 | import butterknife.ButterKnife; 10 | import butterknife.OnClick; 11 | 12 | public class MainActivity extends Activity { 13 | 14 | @BindView(R.id.btn_test1) 15 | Button btnTest1; 16 | 17 | @Override 18 | public void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_main); 21 | ButterKnife.bind(this); 22 | } 23 | 24 | @OnClick(R.id.btn_test1) 25 | public void submit() { 26 | Intent intent = new Intent(this, MyView1Activity.class); 27 | startActivity(intent); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/view/myview/MyView1Activity.java: -------------------------------------------------------------------------------- 1 | package com.example.view.myview; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.os.Message; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.widget.Toast; 8 | 9 | import com.example.view.myview.view.DownProgressView; 10 | 11 | import butterknife.BindView; 12 | import butterknife.ButterKnife; 13 | 14 | public class MyView1Activity extends AppCompatActivity implements DownProgressView.StateProgressListner { 15 | @BindView(R.id.view1) 16 | DownProgressView view1; 17 | int progress; 18 | 19 | @Override 20 | protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | setContentView(R.layout.activity_my_view1); 23 | ButterKnife.bind(this); 24 | view1.setListner(this); 25 | } 26 | 27 | 28 | Handler handler = new Handler() { 29 | @Override 30 | public void handleMessage(Message msg) { 31 | super.handleMessage(msg); 32 | view1.setmProgress(++progress); 33 | handler.sendEmptyMessageDelayed(1, 20); 34 | } 35 | 36 | }; 37 | 38 | @Override 39 | public void onstart() { 40 | handler.sendEmptyMessage(1); 41 | } 42 | 43 | @Override 44 | public void onstop() { 45 | handler.removeMessages(1); 46 | } 47 | 48 | @Override 49 | public void onfinish() { 50 | progress = 0; 51 | Toast.makeText(this, "下载完成了!继续开始", Toast.LENGTH_SHORT).show(); 52 | } 53 | 54 | @Override 55 | protected void onDestroy() { 56 | super.onDestroy(); 57 | handler.removeMessages(1); 58 | view1.onDestory(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/view/myview/view/DownProgressView.java: -------------------------------------------------------------------------------- 1 | package com.example.view.myview.view; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.BitmapFactory; 6 | import android.graphics.Canvas; 7 | import android.graphics.Paint; 8 | import android.graphics.RectF; 9 | import android.util.AttributeSet; 10 | import android.view.MotionEvent; 11 | import android.view.View; 12 | 13 | import com.example.view.myview.R; 14 | 15 | /** 16 | * 模仿苹果下载暂停控件 17 | * Created by WZG on 2016/7/20. 18 | */ 19 | public class DownProgressView extends View { 20 | // 第一圈的颜色 21 | private int mFirstColor; 22 | // 第二圈的颜色 23 | private int mSecondColor; 24 | // 圈的宽度 25 | private int mCircleWidth; 26 | // 画笔 27 | private Paint mPaint; 28 | // 当前进度 29 | private int mProgress; 30 | // 圆环中心点 31 | private int centre; 32 | // 状态图片 33 | private Bitmap bitmap; 34 | // 开始状态图片 35 | private int srcStart; 36 | // 暂停状态图片 37 | private int srcStorp; 38 | // 0开始状态;1暂停;2完成 39 | private int state; 40 | // 回调接口 41 | private StateProgressListner listner; 42 | 43 | public DownProgressView(Context context) { 44 | super(context); 45 | } 46 | 47 | public DownProgressView(Context context, AttributeSet attrs) { 48 | super(context, attrs); 49 | mFirstColor = getResources().getColor(R.color.white); 50 | mSecondColor = getResources().getColor(R.color.progress); 51 | mCircleWidth = 5; 52 | mPaint = new Paint(); 53 | mProgress = 0; 54 | srcStart = R.drawable.btn_vedio_restart; 55 | srcStorp = R.drawable.btn_down_pause; 56 | state = 0; 57 | } 58 | 59 | public DownProgressView(Context context, AttributeSet attrs, int defStyleAttr) { 60 | super(context, attrs, defStyleAttr); 61 | } 62 | 63 | @Override 64 | protected void onDraw(Canvas canvas) { 65 | super.onDraw(canvas); 66 | drawCirle(canvas); 67 | drawBitmap(canvas); 68 | } 69 | 70 | 71 | @Override 72 | public boolean onTouchEvent(MotionEvent event) { 73 | if (event.getAction() == MotionEvent.ACTION_UP) { 74 | // 判断当前状态 75 | if (state == 0) { 76 | stop(); 77 | } else if (state == 1) { 78 | start(); 79 | } 80 | } 81 | return true; 82 | } 83 | 84 | /** 85 | * 圆弧进度 86 | * 87 | * @param canvas 88 | */ 89 | private void drawCirle(Canvas canvas) { 90 | centre = getWidth() / 2; // 获取圆心的x坐标 91 | int radius = centre - mCircleWidth;// 半径 92 | mPaint.setStrokeWidth(mCircleWidth); // 设置圆环的宽度 93 | mPaint.setAntiAlias(true); // 消除锯齿 94 | mPaint.setStyle(Paint.Style.STROKE); // 设置空心 95 | // 用于定义的圆弧的形状和大小的界限 96 | RectF oval = new RectF(centre - radius, centre - radius, centre + radius, centre + radius); 97 | mPaint.setColor(mFirstColor); // 设置圆环的颜色 98 | canvas.drawCircle(centre, centre, radius, mPaint); // 画出圆环 99 | mPaint.setColor(mSecondColor); // 设置圆环的颜色 100 | mPaint.setStrokeCap(Paint.Cap.ROUND);//两边带圆弧 101 | canvas.drawArc(oval, -90, mProgress, false, mPaint); // 根据进度画圆弧 102 | } 103 | 104 | 105 | /** 106 | * 画出当前的状态图标 107 | * 108 | * @param canvas 109 | */ 110 | private void drawBitmap(Canvas canvas) { 111 | if (bitmap != null) bitmap.recycle(); 112 | bitmap = BitmapFactory.decodeResource(getResources(), state == 0 ? srcStart : srcStorp); 113 | if (bitmap != null) { 114 | int with = bitmap.getWidth(); 115 | int height = bitmap.getHeight(); 116 | canvas.drawBitmap(bitmap, centre - with / 2, centre - height / 2, mPaint); 117 | } 118 | } 119 | 120 | 121 | /** 122 | * 停止 123 | */ 124 | private void stop() { 125 | state = 1; 126 | if (listner != null) { 127 | listner.onstart(); 128 | } 129 | invalidate(); 130 | } 131 | 132 | /** 133 | * 开始 134 | */ 135 | private void start() { 136 | state = 0; 137 | if (listner != null) { 138 | listner.onstop(); 139 | } 140 | invalidate(); 141 | } 142 | 143 | public int getmProgress() { 144 | return mProgress; 145 | } 146 | 147 | /** 148 | * 更新进度条 149 | * 150 | * @param mProgress 151 | */ 152 | public void setmProgress(int mProgress) { 153 | this.mProgress = mProgress; 154 | if (mProgress == 360 && listner != null) { 155 | listner.onfinish(); 156 | } 157 | invalidate(); 158 | } 159 | 160 | public void setListner(StateProgressListner listner) { 161 | this.listner = listner; 162 | } 163 | 164 | /** 165 | * 销毁处理 166 | */ 167 | public void onDestory() { 168 | if (bitmap != null) bitmap.recycle(); 169 | } 170 | 171 | /** 172 | * 设置开始状态图片资源 173 | * 174 | * @param srcStart 175 | */ 176 | public void setSrcStart(int srcStart) { 177 | this.srcStart = srcStart; 178 | } 179 | 180 | 181 | /** 182 | * 设置停止状态图片 183 | * 184 | * @param srcStorp 185 | */ 186 | public void setSrcStorp(int srcStorp) { 187 | this.srcStorp = srcStorp; 188 | } 189 | 190 | /** 191 | * 设置加载环的宽度 192 | * 193 | * @param mCircleWidth 194 | */ 195 | public void setmCircleWidth(int mCircleWidth) { 196 | this.mCircleWidth = mCircleWidth; 197 | } 198 | 199 | 200 | /** 201 | * 设置第一个圆环的颜色 202 | * 203 | * @param mSecondColor 204 | */ 205 | public void setmSecondColor(int mSecondColor) { 206 | this.mSecondColor = mSecondColor; 207 | } 208 | 209 | /** 210 | * 设置进度圆环的颜色 211 | * 212 | * @param mFirstColor 213 | */ 214 | public void setmFirstColor(int mFirstColor) { 215 | this.mFirstColor = mFirstColor; 216 | } 217 | 218 | /** 219 | * 自定义监听器 220 | */ 221 | public interface StateProgressListner { 222 | /** 223 | * 开始 224 | */ 225 | void onstart(); 226 | 227 | /** 228 | * 暂停 229 | */ 230 | void onstop(); 231 | 232 | /** 233 | * 结束 234 | */ 235 | void onfinish(); 236 | } 237 | } 238 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/view/myview/view/MyView1.java: -------------------------------------------------------------------------------- 1 | package com.example.view.myview.view; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.graphics.Color; 6 | import android.graphics.Paint; 7 | import android.graphics.RectF; 8 | import android.util.AttributeSet; 9 | import android.util.Log; 10 | import android.view.MotionEvent; 11 | import android.view.View; 12 | 13 | /** 14 | * 第一个自定义view简单点吧 15 | *

16 | * 居中显示一个文本框 17 | * 添加点击监听 18 | * Created by WZG on 2016/7/19. 19 | */ 20 | public class MyView1 extends View { 21 | // 距离边缘的位置 22 | private int pading = 60; 23 | // 边框距离x坐标 24 | private int startX = 100; 25 | // 边框距离y坐标 26 | private int startY = 100; 27 | // 文字的区域 28 | private RectF rectFTxt; 29 | // 边框区域 30 | private RectF rectF; 31 | 32 | 33 | public MyView1(Context context) { 34 | super(context); 35 | } 36 | 37 | public MyView1(Context context, AttributeSet attrs) { 38 | super(context, attrs); 39 | } 40 | 41 | public MyView1(Context context, AttributeSet attrs, int defStyleAttr) { 42 | super(context, attrs, defStyleAttr); 43 | } 44 | 45 | @Override 46 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 47 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 48 | } 49 | 50 | @Override 51 | protected void onDraw(Canvas canvas) { 52 | super.onDraw(canvas); 53 | paintCenterText("我就是一个文本显示的控件呀", canvas); 54 | } 55 | 56 | /** 57 | * 绘制一个居中显示的textview 58 | */ 59 | private void paintCenterText(String name, Canvas canvas) { 60 | Paint textPaint = new Paint(); 61 | textPaint.setColor(Color.BLACK); 62 | textPaint.setTextSize(40); 63 | /** 64 | * 设置绘制文字时起始点X坐标的位置 65 | * CENTER:以文字的宽度的中心点为起始点向两边绘制 66 | * LEFT:以文字左边为起始点向右边开始绘制 67 | * RIGHT:以文字宽度的右边为起始点向左边绘制 68 | */ 69 | textPaint.setTextAlign(Paint.Align.CENTER); 70 | Paint.FontMetrics fm = textPaint.getFontMetrics(); 71 | float textHeight = (int) Math.ceil(fm.bottom - fm.top); 72 | float textWith = textPaint.measureText(name); 73 | 74 | 75 | rectF = new RectF(startX, startY, startX + textWith + pading * 2, pading * 2 + startY + textHeight); 76 | Paint paint = new Paint(); 77 | paint.setColor(Color.YELLOW); 78 | 79 | rectFTxt = new RectF(startX + pading, startY + pading, rectF.right - pading, rectF.bottom - pading); 80 | canvas.drawRect(rectF, paint); 81 | 82 | int baseline = (int) ((rectF.bottom + rectF.top - fm.bottom - fm.top) / 2); 83 | canvas.drawText(name, rectF.centerX(), baseline, textPaint); 84 | } 85 | 86 | 87 | @Override 88 | public boolean onTouchEvent(MotionEvent event) { 89 | float x = 0; 90 | float y = 0; 91 | switch (event.getAction()) { 92 | case MotionEvent.ACTION_DOWN: 93 | case MotionEvent.ACTION_MOVE: 94 | x = event.getX(); 95 | y = event.getY(); 96 | case MotionEvent.ACTION_UP: 97 | if (x > rectFTxt.left && x < rectFTxt.right && y > rectFTxt.top && y < rectFTxt.bottom) { 98 | Log.i("tag", "文字被点击了!"); 99 | } 100 | if (x > rectF.left && x < rectFTxt.left) { 101 | Log.i("tag", "空白左的地方被点击了!"); 102 | } 103 | if (x > rectFTxt.right && x < rectF.right) { 104 | Log.i("tag", "空白右的地方被点击了!"); 105 | } 106 | if (y > rectF.top && y < rectFTxt.top) { 107 | Log.i("tag", "空白上的地方被点击了!"); 108 | } 109 | if (y > rectFTxt.bottom && y < rectF.bottom) { 110 | Log.i("tag", "空白下的地方被点击了!"); 111 | } 112 | break; 113 | } 114 | return true; 115 | } 116 | 117 | 118 | public int getFontHeight(float fontSize) { 119 | Paint paint = new Paint(); 120 | paint.setTextSize(fontSize); 121 | Paint.FontMetrics fm = paint.getFontMetrics(); 122 | return (int) Math.ceil(fm.descent - fm.top) + 2; 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/btn_down_pause.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wzgiceman/DownProgressView/a84c14e050b5ce52fa942f342eda419e50b83b10/app/src/main/res/drawable-xxhdpi/btn_down_pause.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/btn_vedio_restart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wzgiceman/DownProgressView/a84c14e050b5ce52fa942f342eda419e50b83b10/app/src/main/res/drawable-xxhdpi/btn_vedio_restart.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/btn_down_pause.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wzgiceman/DownProgressView/a84c14e050b5ce52fa942f342eda419e50b83b10/app/src/main/res/drawable-xxxhdpi/btn_down_pause.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/btn_vedio_restart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wzgiceman/DownProgressView/a84c14e050b5ce52fa942f342eda419e50b83b10/app/src/main/res/drawable-xxxhdpi/btn_vedio_restart.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 |