本文實(shí)例講述了Android開(kāi)發(fā)之自定義星星評(píng)分控件RatingBar用法。分享給大家供大家參考,具體如下:
創(chuàng)新互聯(lián)公司是一家以重慶網(wǎng)站建設(shè)公司、網(wǎng)頁(yè)設(shè)計(jì)、品牌設(shè)計(jì)、軟件運(yùn)維、成都網(wǎng)站營(yíng)銷(xiāo)、小程序App開(kāi)發(fā)等移動(dòng)開(kāi)發(fā)為一體互聯(lián)網(wǎng)公司。已累計(jì)為衛(wèi)生間隔斷等眾行業(yè)中小客戶(hù)提供優(yōu)質(zhì)的互聯(lián)網(wǎng)建站和軟件開(kāi)發(fā)服務(wù)。
星級(jí)評(píng)分條RatingBar類(lèi)似于SeekBar、ProgressBar'等等都可以自定義樣式
它的主要用途就比如淘寶、景點(diǎn) 滿(mǎn)意度等
這里給出兩種自定義效果
如圖所示 第一種是通過(guò)RatingBar獲得分?jǐn)?shù) 第二個(gè)是通過(guò)RatingBar動(dòng)態(tài)調(diào)節(jié)控件屬性(透明度)
由于RatngBar使用簡(jiǎn)單
自定義樣式方法和 https://www.jb51.net/article/158338.htm一樣
在drawable中建一個(gè)xml文件寫(xiě)一個(gè) layer-list 就行
這里直接給出它的使用方法:
public class MainActivity extends Activity { RatingBar ratingBar ;RatingBar ratingBar02 ; TextView textView ; ImageView imageView ; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ratingBar = (RatingBar) findViewById(R.id.rating); ratingBar02 = (RatingBar) findViewById(R.id.rating02); textView = (TextView) findViewById(R.id.textview); imageView = (ImageView) findViewById(R.id.image); ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() { @Override public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { textView.setText(String.valueOf((int) (rating))); } }); ratingBar02.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() { @Override public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { imageView.setAlpha((int)(rating*255/5)); } }); } }
然后是布局文件:
文件中的屬性 與ProgressBar一樣
<?xml version="1.0" encoding="utf-8" ?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:id="@+id/textview" android:layout_width="match_parent" android:layout_height="75dp" android:gravity="center_horizontal" android:textSize="50dp"/> <!--android:progressDrawable自定義樣式--> <RatingBar android:id="@+id/rating" android:layout_width="match_parent" android:layout_height="wrap_content" android:numStars="5" android:max="255" android:progress="255" android:stepSize="0.5"/> <ImageView android:id="@+id/image" android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/huangjindiao"/> <RatingBar android:id="@+id/rating02" android:layout_width="match_parent" android:layout_height="wrap_content" android:numStars="5" android:progressDrawable="@drawable/my_bar" android:stepSize="0.5"/> </LinearLayout>
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《Android控件用法總結(jié)》、《Android開(kāi)發(fā)入門(mén)與進(jìn)階教程》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android數(shù)據(jù)庫(kù)操作技巧總結(jié)》及《Android資源操作技巧匯總》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
文章標(biāo)題:Android開(kāi)發(fā)之自定義星星評(píng)分控件RatingBar用法示例
分享鏈接:http://aaarwkj.com/article30/ijpgso.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開(kāi)發(fā)、ChatGPT、外貿(mào)建站、定制開(kāi)發(fā)、搜索引擎優(yōu)化、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)