android自定义View,带旋转动画的饼状图,区块点击事件,滑动到某一区块事件,可惯性旋转
PieRotateView:这是一个可旋转,自动回弹,可惯性旋转的饼状图,多属性控制,使用简单,具备一个自定义View应有的基本素质
常规使用 | 下拉刷新及其他滑动冲突 |
---|---|
属性 | 类型 | 作用 |
---|---|---|
name | String | 表示该扇形区块的名字 |
num | float | 表示该扇形区块的数字(决定它的百分比占比,总数为所有的PieRotateViewModel num叠加) |
color | int | 表示该扇形区块的颜色 |
percent | String | 表示该扇形区块所占的百分比 |
方法 | 参数 | 作用 |
---|---|---|
setEnableTouch | boolean | 设置是否可以消费事件(默认为true) |
setPieRotateViewModelList | List<PieRotateViewModel> | 设置Data |
setFling | boolean | 设置是否可以惯性滑动 |
setRecoverTime | int | 设置回弹动画的时长 |
setCircleColor | int | 设置中间遮罩圆的颜色 |
setTextColor | int | 设置中间Text文本的颜色 |
setArrawColor | int | 设置下方指针箭头的颜色 |
setOnSelectionListener | PieRotateView.onSelectionListener | 指针指向某个区块以及点击事件指向的区块事件回调 |
setOnPromiseParentTouchListener | PieRotateView.onPromiseParentTouchListener | 通知外界是否允许pierotateview之上的view拦截事件 |
notifyDataChanged | void | 通知pierotateview数据源发生了改变,重置相关初始属性,刷新View |
notifySettingChanged | void | 通知pierotateview某些设置发生了改变,刷新View |
Step 1. Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.NoEndToLF:PieRotateView:1.0.3'
}
<com.wxy.pierotateview.view.PieRotateView
android:layout_width="match_parent"
android:padding="20dp"
android:id="@+id/pie"
android:layout_height="wrap_content"></com.wxy.pierotateview.view.PieRotateView>
List<PieRotateViewModel> list = new ArrayList<>();
list.add(new PieRotateViewModel("红扇", 20, getResources().getColor(R.color.colorAccent)));
list.add(new PieRotateViewModel("绿扇", 10, getResources().getColor(R.color.colorPrimaryDark)));
list.add(new PieRotateViewModel("蓝扇", 10, Color.BLUE));
list.add(new PieRotateViewModel("黄扇", 60, Color.parseColor("#FF7F00")));
list.add(new PieRotateViewModel("粉扇", 50, Color.parseColor("#EE7AE9")));
pie.setPieRotateViewModelList(list);
swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
pie.setEnableTouch(false);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
list.clear();
list.add(new PieRotateViewModel("红扇", 20, getResources().getColor(R.color.colorAccent)));
list.add(new PieRotateViewModel("绿扇", 10, getResources().getColor(R.color.colorPrimaryDark)));
pie.notifyDataChanged();
swipe.setRefreshing(false);
pie.setEnableTouch(true);
}
},2000);
}
});
pie.setOnSelectionListener(new PieRotateView.onSelectionListener() {
@Override
public void onSelect(int position, String percent) {
tvName.setText(list.get(position).getName() + "数额:" + list.get(position).getNum() + " 占比:" + percent);
tvName.setTextColor(list.get(position).getColor());
}
});
pie.setOnPromiseParentTouchListener(new PieRotateView.onPromiseParentTouchListener() {
@Override
public void onPromiseTouch(boolean promise) {
swipe.setEnabled(promise);
}
});
方法 | 参数 | 作用 |
---|---|---|
setFling | boolean | 设置是否可以惯性滑动 |
setRecoverTime | int | 设置回弹动画的时长 |
setCircleColor | int | 设置中间遮罩圆的颜色 |
setTextColor | int | 设置中间Text文本的颜色 |
setArrawColor | int | 设置下方指针箭头的颜色 |
Copyright (c) [2018] [static]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.