欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android開發(fā)之自定義星星評分控件RatingBar用法示例

 更新時間:2019年03月23日 11:49:02   作者:水中魚之1999  
這篇文章主要介紹了Android開發(fā)之自定義星星評分控件RatingBar用法,結合具體實例形式分析了Android自定義評分控件的具體實現(xiàn)步驟以及功能、布局相關操作技巧,需要的朋友可以參考下

本文實例講述了Android開發(fā)之自定義星星評分控件RatingBar用法。分享給大家供大家參考,具體如下:

星級評分條RatingBar類似于SeekBar、ProgressBar'等等都可以自定義樣式

它的主要用途就比如淘寶、景點 滿意度等

這里給出兩種自定義效果

如圖所示 第一種是通過RatingBar獲得分數(shù) 第二個是通過RatingBar動態(tài)調節(jié)控件屬性(透明度)

由于RatngBar使用簡單

自定義樣式方法和 http://www.dbjr.com.cn/article/158338.htm一樣

在drawable中建一個xml文件寫一個 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>

更多關于Android相關內(nèi)容感興趣的讀者可查看本站專題:《Android控件用法總結》、《Android開發(fā)入門與進階教程》、《Android視圖View技巧總結》、《Android編程之a(chǎn)ctivity操作技巧總結》、《Android數(shù)據(jù)庫操作技巧總結》及《Android資源操作技巧匯總

希望本文所述對大家Android程序設計有所幫助。

相關文章

最新評論