文件名称:评级星星效果
文件大小:443KB
文件格式:ZIP
更新时间:2017-03-01 10:22:57
android
package com.example.startest; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.widget.RatingBar; import android.widget.RatingBar.OnRatingBarChangeListener; import android.widget.TextView; public class MainActivity extends Activity implements OnRatingBarChangeListener{ private RatingBar mSmallRatingBar; private RatingBar mIndicatorRatingBar; private TextView mRatingText; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mRatingText = (TextView) findViewById(R.id.rating); // We copy the most recently changed rating on to these indicator-only // rating bars mIndicatorRatingBar = (RatingBar) findViewById(R.id.indicator_ratingbar); mSmallRatingBar = (RatingBar) findViewById(R.id.small_ratingbar); // The different rating bars in the layout. Assign the listener to us. ((RatingBar)findViewById(R.id.ratingbar1)).setOnRatingBarChangeListener(this); ((RatingBar)findViewById(R.id.ratingbar2)).setOnRatingBarChangeListener(this); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { // TODO Auto-generated method stub final int numStars = ratingBar.getNumStars(); mRatingText.setText( " 受欢迎度" + rating + "/" + numStars); // Since this rating bar is updated to reflect any of the other rating // bars, we should update it to the current values. if (mIndicatorRatingBar.getNumStars() != numStars) { mIndicatorRatingBar.setNumStars(numStars); mSmallRatingBar.setNumStars(numStars); } if (mIndicatorRatingBar.getRating() != rating) { mIndicatorRatingBar.setRating(rating); mSmallRatingBar.setRating(rating); } final float ratingBarStepSize = ratingBar.getStepSize(); if (mIndicatorRatingBar.getStepSize() != ratingBarStepSize) { mIndicatorRatingBar.setStepSize(ratingBarStepSize); mSmallRatingBar.setStepSize(ratingBarStepSize); } } }
【文件预览】:
StarTest
----bin()
--------res()
--------classes()
--------AndroidManifest.xml(880B)
----res()
--------drawable-ldpi()
--------values-v11()
--------menu()
--------values-v14()
--------drawable-hdpi()
--------drawable-xhdpi()
--------drawable-xxhdpi()
--------values()
--------values-sw720dp-land()
--------drawable-mdpi()
--------values-sw600dp()
--------layout()
----proguard-project.txt(781B)
----ic_launcher-web.png(50KB)
----assets()
----gen()
--------com()
----.settings()
--------org.eclipse.jdt.core.prefs(177B)
----src()
--------com()
----.project(844B)
----.classpath(364B)
----project.properties(563B)
----AndroidManifest.xml(880B)
----libs()
--------android-support-v4.jar(384KB)