怎么在Android中自定义View实现投票进度条

发布时间:2021-05-27 17:47:56 作者:Leah
来源:亿速云 阅读:190

这篇文章将为大家详细讲解有关怎么在Android中自定义View实现投票进度条,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

功能属性介绍

<!-- MatchSupportProgressBar -->
  <declare-styleable name="MatchSupportProgressBar">
  <!-- 进度条圆角角度 -->
  <attr name="progress_radio" format="string"></attr>
  <!-- 进度条左侧Tag文本 -->
  <attr name="progress_tag_text" format="string"></attr>
  <!-- 进度条已填充部分颜色 -->
  <attr name="progress_reach_color" format="color"></attr>
  <!-- 进度条已填充部分高度 -->
  <attr name="progress_reach_height" format="dimension"></attr>
  <!-- 进度条背景颜色 -->
  <attr name="progress_background_color" format="color"></attr>
  <!-- 进度条背景高度 -->
  <attr name="progress_background_height" format="dimension"></attr>
  <!-- 进度条左侧Tag文本颜色 -->
  <attr name="progress_tag_text_color" format="color"></attr>
  <!-- 进度条左侧Tag文本尺寸 -->
  <attr name="progress_tag_text_size" format="dimension"></attr>
  <!-- 进度条右侧百分比文本颜色 -->
  <attr name="progress_percent_text_color" format="color"></attr>
  <!-- 进度条右侧百分比文本尺寸 -->
  <attr name="progress_percent_text_size" format="dimension"></attr>
  <!-- 进度条右侧百分比文本 -->
  <attr name="progress_percent_text" format="string"></attr>
  <!-- 进度条选中的图标与进度条、文字的间距 -->
  <attr name="progress_offsetX" format="dimension"></attr>
  <!-- 进度条右侧文字的水平偏移量 -->
  <attr name="progress_offsetR" format="dimension"></attr>
  <!-- 进度条之间的偏移量 -->
  <attr name="progress_LineSpacing" format="dimension"></attr>
</declare-styleable>

xml使用示例

<com.yjyc.supportprogress.view.MatchSupportProgressBar
  android:id="@+id/progressbar_match_support"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_marginTop="10dp"
  android:paddingLeft="3dp"
  android:paddingRight="3dp"
  android:progress="30"
  yjcp:progress_background_color="#333"
  yjcp:progress_background_height="30dp"
  yjcp:progress_offsetR="20dp"
  yjcp:progress_percent_text_color="#345698"
  yjcp:progress_percent_text_size="13sp"
  yjcp:progress_reach_color="#999"
  yjcp:progress_tag_text_color="#ffffff"
  yjcp:progress_tag_text="杰伦;那英;汪峰"
  yjcp:progress_tag_text_size="13sp" />

java使用示例

//进度条的点击事件监听
mspb.setOnRightTextClickListener(new OnRightTextClickListener() {

 @Override
 public void onClick(int position) {
 //position是点击的位置
 }
});
/*
为进度条赋值:
参数1:是我们算好的进度值,一般由服务器返回。(注: yjcp:progress_tag_text="杰伦;那英;汪峰"设置 了几个字符串,getPercentList就要传几个字符串)
参数2:得到一个boolean类型的集合,用于设置进度条√显示的位置
参数3:true表示已投票,false表示未投票
参数4:是否开启动画特效 
*/
mspb.setPercentState(getPercentList("10","90","100"), getCheckList(position), true, true);
//重置进度条状态,如果在listview中涉及到复用问题条用它即可。
//参数:true投过票,false未投过
mspb.setState(false);

关于怎么在Android中自定义View实现投票进度条就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

推荐阅读:
  1. 小程序实现投票进度条
  2. Android自定义View如何实现圆环进度条

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

android

上一篇:使用surfaceView怎么实现切换效果

下一篇:怎么在Android中自定义View实现地铁显示牌效果

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》