Android 仿支付宝中的余额宝收益进度条

作者:Susan8888 时间:2022-11-23 03:58:33 

一、 看效果

Android 仿支付宝中的余额宝收益进度条

二、上代码


package com.framework.widget;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.View;
import com.R;
/**
* @author dahai
* @ClassName: (仿支付宝) 收益进度条
* @Description: ${todo}
* @date ${date} ${time}
* @email 202491024@qq.com
* @since $
  • android


  • 进度条



  • */


  • public class ProfitProgerssBar extends View {


  • //背景色


  • private static final int DEFAULT_BACK_COLOR = Color.parseColor("#ffffff");


  • //字的颜色


  • private static final int DEFAULT_TEXT_COLOR = Color.parseColor("#ffffff");


  • //进度条背景颜色


  • private static final int DEFAULT_PROGRESS_COLOR = Color.parseColor("#abacaf");


  • //进度条默认的高度


  • private static final float DEFAULT_PROGRESS_HEIGHT =120f;


  • //文字的大小


  • private static final float DEFAULT_TEXT_SIZE = 50;


  • /**


  •  * 收益进度条左右两边margin大小


  •  */


  • private static final int MARGIN_SIZE = 20;


  • private Context context;


  • /**


  •  * 背景颜色的画笔


  •  */


  • private Paint backgroundPaint;


  • /**


  •  * 收益进度颜色的画笔


  •  */


  • private Paint progressPaint;


  • /**


  •  * 画文字的画笔


  •  */


  • private Paint textPaint;


  • /**


  •  * 背景的宽度


  •  */


  • private int view_background_width;


  • /**


  •  * 背景的高度


  •  */


  • private float view_background_height = DEFAULT_PROGRESS_HEIGHT;


  • /**


  •  * 日期


  •  */


  • private String date = "2016/12/07";


  • /**


  •  * 描叙(百分比/元)


  •  */


  • private String desc = "2.1234";


  • /**


  •  * 要显示的长度的百分比


  •  */


  • private int progress = 70;


  • //进度条颜色


  • private int progress_color = DEFAULT_PROGRESS_COLOR;


  • //背景色


  • private int progress_back_color = DEFAULT_BACK_COLOR;


  • //字的颜色


  • private int text_color = DEFAULT_TEXT_COLOR;


  • //字的大小


  • private float TEXT_SIZE = DEFAULT_TEXT_SIZE;


  • public ProfitProgerssBar(Context context) {


  •  super(context);


  •  initView(context);


  • }


  • public ProfitProgerssBar(Context context, AttributeSet attrs) {


  •  super(context, attrs);


  •  initView(context);


  • }


  • public ProfitProgerssBar(Context context, AttributeSet attrs, int defStyleAttr) {


  •  super(context, attrs, defStyleAttr);


  •  initView(context);


  • }


  • private void initView(Context context) {


  •  this.context = context;


  •  TypedArray typedArray = this.context.obtainStyledAttributes(R.styleable.ProfitProgerssBar);


  •  progress_back_color = typedArray.getColor(R.styleable.ProfitProgerssBar_progress_backg_color,DEFAULT_BACK_COLOR);


  •  text_color = typedArray.getColor(R.styleable.ProfitProgerssBar_progress_text_color,DEFAULT_TEXT_COLOR);


  •  TEXT_SIZE = typedArray.getDimension(R.styleable.ProfitProgerssBar_progress_text_size,DEFAULT_TEXT_SIZE);


  •  backgroundPaint = new Paint();


  •  backgroundPaint.setStrokeWidth(10);


  •  backgroundPaint.setColor(progress_back_color);


  •  backgroundPaint.setDither(true);


  •  backgroundPaint.setAntiAlias(true);


  •  progressPaint = new Paint();


  •  progressPaint.setStrokeWidth(10);


  •  progressPaint.setDither(true);


  •  progressPaint.setAntiAlias(true);


  •  textPaint = new Paint();


  •  textPaint.setStrokeWidth(10);


  •  textPaint.setDither(true);


  •  textPaint.setAntiAlias(true);


  •  textPaint.setTextSize(TEXT_SIZE);


  •  DisplayMetrics d = new DisplayMetrics();


  •  ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(d);


  •  view_background_width = d.widthPixels;


  • }


  • /**


  •  * 初始化 进度条


  •  * @param date


  •  * @param desc


  •  * @param progress


  •  * @param progressColor


  •  */


  • public void init(String date,String desc,int progress,int progressColor){


  •  this.date = date;


  •  this.desc = desc;


  •  this.progress = progress;


  •  this.progress_color = progressColor;


  • }


  • @Override


  • protected void onDraw(Canvas canvas) {


  •  super.onDraw(canvas);


  •  view_background_height = this.getMeasuredHeight();


  •  RectF r = new RectF();


  •  r.left = 0;


  •  r.top = 0;


  •  r.right = view_background_width;


  •  r.bottom = view_background_height;////------------------------


  •  canvas.drawRect(r, backgroundPaint);


  •  RectF r1 = new RectF();


  •  r1.left = 0;


  •  r1.top = 0;


  •  r1.right = view_background_width * progress / 100;


  •  r1.bottom = view_background_height;////------------------------


  •  progressPaint.setColor(progress_color);


  •  canvas.drawRect(r1, progressPaint);


  •  textPaint.setColor(text_color);


  •  Rect r2 = new Rect();


  •  textPaint.getTextBounds(date,0,date.length(),r2);


  •  canvas.drawText(date, MARGIN_SIZE, (view_background_height-r2.top)/2, textPaint);//日期


  •  Rect r3 = new Rect();


  •  textPaint.getTextBounds(desc,0,desc.length(),r3);


  •  if(progress>95&&progress<100){


  •   canvas.drawText(desc, r1.right-textPaint.measureText(desc)-MARGIN_SIZE-30,(view_background_height-r3.top)/2, textPaint);


  •  }else if(progress>=100) {


  •   canvas.drawText(desc, r1.right-textPaint.measureText(desc)-MARGIN_SIZE-45,(view_background_height-r3.top)/2, textPaint);


  •  }else {


  •   canvas.drawText(desc, r1.right - textPaint.measureText(desc) - MARGIN_SIZE, (view_background_height - r3.top) / 2, textPaint);


  •  }


  •  invalidate();


  • }


  • }

三、


<com.framework.widget.ProfitProgerssBar
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
app:progress_back_color="@color/white"
app:progress_text_color="@color/white"
app:progress_text_size="14dp"
android:id="@+id/profitProgerssBar"
/>
<declare-styleable name="ProfitProgerssBar">
<attr name="progress_backg_color" format="color"/>
<attr name="progress_text_color" format="color"/>
<attr name="progress_text_size" format="dimension"/>
</declare-styleable>

以上所述是小编给大家介绍的Android 仿支付宝中的余额宝收益进度条网站的支持!

来源:http://blog.csdn.net/susan8888/article/details/53538068

标签:android,进度条
0
投稿

猜你喜欢

  • Mybatis plus中的like查询问题

    2022-03-18 09:14:30
  • SpringBoot之Helloword 快速搭建一个web项目(图文)

    2023-08-23 17:36:21
  • 详细解读java同步之synchronized解析

    2022-08-01 15:27:05
  • Android实现屏幕录制功能

    2022-10-29 15:26:36
  • 解决PhoneGap不支持viewport的几种方法

    2023-03-13 01:51:15
  • Java AQS信号量Semaphore的使用

    2021-06-11 17:10:44
  • Java并发编程之LockSupport类详解

    2022-08-21 10:38:36
  • java 域对象共享数据的实现

    2022-04-26 15:22:14
  • AccessibilityService实现微信发红包功能

    2023-06-23 03:51:53
  • java实现合并单元格的同时并导出excel示例

    2022-05-15 04:22:38
  • SpringBoot面试突击之过滤器和拦截器区别详解

    2022-10-13 02:02:05
  • 优化SimpleAdapter适配器加载效率的方法

    2022-03-10 20:33:32
  • Java监听器的作用及用法代码示例

    2023-06-24 06:59:07
  • Unity实现轮盘方式的按钮滚动效果

    2022-06-19 16:53:57
  • Android EventBus(普通事件/粘性事件)详解

    2022-12-22 18:48:09
  • C#中的const和readonly关键字详解

    2023-02-21 17:44:22
  • Android仿微信列表滑动删除之可滑动控件(一)

    2021-12-24 21:15:46
  • Android四大组件之broadcast广播使用讲解

    2023-07-27 12:41:50
  • Json操作库DynamicJson使用指南

    2023-06-17 10:17:35
  • IDEA内存调试插件(好用)

    2022-04-19 08:51:13
  • asp之家 软件编程 m.aspxhome.com