Android自定義View實現投票進度條
阿新 • • 發佈:2020-01-07
本文例項為大家分享了Android投票進度條的具體程式碼,供大家參考,具體內容如下
效果展示
功能屬性介紹
<!-- 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投票進度條
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。