0

下面是工作的示例代码我如何使评级栏图标变小?如果我添加这条线 style="?android:attr/ratingBarStyleSmall" 那么评级栏不起作用为什么?hw使评级图标变小请帮帮我

  <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
 android:orientation="vertical" >

<TextView
    android:id="@+id/lblRateMe"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/text_label_1"
    android:textAppearance="?android:attr/textAppearanceMedium" />

 <RatingBar
    android:id="@+id/ratingBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:numStars="4"
    android:stepSize="1.0"
    android:rating="2.0" />

  <Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_label" />

 <LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/lblResult"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/text_label_2"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/txtRatingValue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=""
        android:textAppearance="?android:attr/textAppearanceSmall" />

  </LinearLayout>

   </LinearLayout>

public class MainActivity extends Activity {


 private RatingBar ratingBar;
 private TextView ratingValue;
 private Button button;

  @Override
    public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

addListenerOnRatingBar();
addListenerOnButton();

    }

 public void addListenerOnRatingBar() {

ratingBar = (RatingBar) findViewById(R.id.ratingBar);
ratingValue = (TextView) findViewById(R.id.txtRatingValue);


ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {

    public void onRatingChanged(RatingBar ratingBar, float rating,  boolean fromUser) {

        ratingValue.setText(String.valueOf(rating));

    }
});
  }

  public void addListenerOnButton() {

ratingBar = (RatingBar) findViewById(R.id.ratingBar);
button = (Button) findViewById(R.id.button);


button.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {

    Toast.makeText(MainActivity.this, String.valueOf(ratingBar.getRating()),     
  Toast.LENGTH_LONG).show();
    }

});

 }
 }
4

0 回答 0