1
我實現ratingbar
,我想設置ratingbar
像下面附加的圖像,但問題是,當我使用ratingbar
的ratingbar
寬度match_parent
那麼多的五星級表演。任何人都可以幫助我如何實現我的評級欄作爲附加圖像或建議我如何實現它。 這裏是我的activity_main的Android如何增加高度和星的寬度的RatingBar
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="gymtrainer.com.ratinbarexample.MainActivity">
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:text="Rate 5 star for RatingBar"
/>
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
style="@style/foodRatingBar"
android:id="@+id/ratingbar_default"
android:maxWidth="250dp"
android:numStars="5"
android:stepSize="0.1"
/>
<TextView
android:id="@+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="show state up checkbox"
android:textColor="#CC00CC"
android:textSize="20dp"
/>
</LinearLayout>
這是我的主要活動。
public class MainActivity extends Activity {
RatingBar ratingbar1;
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButtonClick();
}
public void addListenerOnButtonClick(){
final TextView text = (TextView) findViewById(R.id.textView);
final RatingBar ratingBar_default = (RatingBar)findViewById(R.id.ratingbar_default);
final Button button = (Button)findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ratingBar_default.setRating(5);
text.setText("Rating: "+String.valueOf(ratingBar_default.getRating()));
}
});
ratingBar_default.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener(){
@Override
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
// TODO Auto-generated method stub
text.setText("Rating: "+String.valueOf(rating));
}});
}
}
這是我的風格
<style name="foodRatingBar" parent="@android:style/Widget.RatingBar">
<item name="android:progressDrawable">@drawable/star_rating_bar_full</item>
<item name="android:minHeight">100dip</item>
<item name="android:maxHeight">100dip</item>
</style>
Android不會縮放圖標。所以只需使用你的自定義圖標,並設置'minHeight'和'maxHeight'。 – Ironman
我使用自定義庫編譯'com.iarcuschin:simpleratingbar:0.0.10' – amorenew
@ amorenew謝謝你的幫助。沒有任何圖書館不可能做這件事情嗎? –