Android使用view仿支付宝月账单
作者:匡效国 时间:2022-03-08 22:54:28
前言
昨夜同门云集推杯又换盏,今朝茶凉酒寒豪言成笑谈。半生累,尽徒然,碑文完美有谁看,隐居山水之间誓与浮名散。
简介
今天给大家带来的是支付宝的月账单view的实现,看到标题,你可能会觉得是自定义view的相关实现,这里可能要让你失望了,因为这里我们用的是github上的一个开源项目。
1. 效果图
2. MPAndroidChart
我们用的是MPAndroidChart打开链接来实现的效果,它可以实现柱状图,饼状图等。
使用方法
1. 添加依赖
你可以选择在build.gradle中添加依赖。
dependencies {
compile 'com.github.PhilJay:MPAndroidChart:v3.0.1'
}
2. 引入library
当然也可以选择引入library。
3. xml引用
activity_main.xml
<com.github.mikephil.charting.charts.PieChart
android:id="@+id/chart_view"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_centerInParent="true" />
4. MainActivity
public class MainActivity extends AppCompatActivity {
private static final float TEXT_SIZE = 18;
private PieChart mPieChart;
private List<MonthData> mMonthData;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mPieChart = (PieChart) findViewById(R.id.chart_view);
initData();
initPieData();
}
private void initData() {
mMonthData = new ArrayList<>();
MonthData playing = new MonthData();
playing.setLabel("娱乐");
playing.setValue(213);
MonthData pay = new MonthData();
pay.setLabel("消费");
pay.setValue(239);
MonthData shopping = new MonthData();
shopping.setLabel("网购");
shopping.setValue(682);
MonthData mobile = new MonthData();
mobile.setLabel("线下");
mobile.setValue(100);
mMonthData.add(playing);
mMonthData.add(pay);
mMonthData.add(shopping);
mMonthData.add(mobile);
}
private void initPieData() {
PieData mPieData = new PieData();
List<PieEntry> mEntry = new ArrayList<>();
String mLabel = "其他";
for (MonthData monthData : mMonthData) {
PieEntry entry = new PieEntry(monthData.getValue(), monthData.getLabel());
mEntry.add(entry);
}
PieDataSet mDataSet = new PieDataSet(mEntry, mLabel);
mDataSet.setColors(Color.rgb(60, 179, 113), Color.rgb(255, 69, 0),
Color.rgb(255, 185, 15), Color.rgb(30, 144, 255));
mPieData.setDataSet(mDataSet);
mPieData.setValueTextSize(TEXT_SIZE);
mPieData.setValueTextColor(Color.WHITE);
mPieChart.setDescription(new Description());
mPieChart.setData(mPieData);
}
}
这里,MonthData是我们自己定义的model,而initPieData()方法中的类都是用的MPAndroidChart中提供的,然后我们再进行简单的封装,并用其提供的api显示view。
5. MonthData
封装的model
public class MonthData {
private String label;
private float value;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public float getValue() {
return value;
}
public void setValue(float value) {
this.value = value;
}
}
总结
对于本次view的实现,虽然我们自己的东西很少,但至少可以让我们有所提高,做出来总比做不出来的好,也希望你能和我一样,每天提高一点,不为别的,充实就好。
源码下载
来源:https://blog.csdn.net/kuangxiaoguo0123/article/details/53282809
标签:Android,支付宝,账单
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java如何获取word文档的条目化内容
2023-10-27 15:04:32
![](https://img.aspxhome.com/file/2023/6/97786_0s.jpg)
Android ViewPager实现图片轮播效果
2023-03-20 17:00:58
![](https://img.aspxhome.com/file/2023/7/98627_0s.jpg)
Android SQLite数据库的增 删 查找操作
2023-02-09 09:47:25
![](https://img.aspxhome.com/file/2023/9/99809_0s.png)
基于Java的MathML转图片的方法(示例代码)
2023-11-25 14:29:39
![](https://img.aspxhome.com/file/2023/3/76503_0s.png)
c# Linq查询详解
2023-05-23 20:43:50
![](https://img.aspxhome.com/file/2023/0/68620_0s.png)
C#中的委托使用
2021-08-12 09:36:57
Android实现极简打开摄像头
2022-09-10 15:56:51
![](https://img.aspxhome.com/file/2023/2/96802_0s.jpg)
SpringBoot实战之高效使用枚举参数(原理篇)案例详解
2022-02-10 23:54:23
![](https://img.aspxhome.com/file/2023/5/77055_0s.jpg)
java中生产者消费者问题和代码案例
2023-11-24 04:09:07
最优雅地整合 Spring & Spring MVC & MyBatis 搭建 Java 企业级应用(附源码)
2023-09-26 18:27:57
![](https://img.aspxhome.com/file/2023/2/77112_0s.png)
Android中通过RxJava进行响应式程序设计的入门指南
2023-06-27 08:17:46
SpringBoot结合JWT登录权限控制的实现
2023-10-06 04:54:22
C#中fixed关键字的作用总结
2023-07-17 09:43:44
Spring Cloud集成Nacos Config动态刷新源码剖析
2022-04-16 11:35:13
![](https://img.aspxhome.com/file/2023/7/83557_0s.png)
Android 8.0如何完美适配全局dialog悬浮窗弹出
2023-04-09 12:54:00
![](https://img.aspxhome.com/file/2023/8/90138_0s.png)
带你走进Maven的大门-最全Maven配置及集成idea工具总结
2022-12-06 08:41:40
![](https://img.aspxhome.com/file/2023/0/60680_0s.png)
java简单实现多线程及线程池实例详解
2023-05-12 05:47:04
Spring boot Mybatis 整合(完整版)
2023-03-28 17:14:32
![](https://img.aspxhome.com/file/2023/3/87143_0s.png)
C#实现截图工具小项目
2023-10-02 08:20:03
Java 随机生成任意组电话号码过程解析
2022-12-27 21:24:02
![](https://img.aspxhome.com/file/2023/6/89626_0s.png)