我想通過我的Android應用程序中的提示對話框顯示評級欄。我面臨的問題是,根據屏幕的寬度,在橫向模式下,評分欄顯示超過5顆星(最多10顆),而函數setNumStars()不起作用。有些帖子已經處理了這個問題,但他們處理的是一個等級欄,它的靜態定義是我動態創建的。如何解決這個問題呢?Android RatingBar顯示超過5顆星
public class MainActivity extends Activity {
private Button launchButton;
//Rating dialog
private AlertDialog.Builder rater;
private RatingBar ratingBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
launchButton =(Button)findViewById(R.id.ratingButton);
launchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//Here the alert dialog will be launched
showRatingDialog();
}
});
//Setting up rating dialog
rater = new AlertDialog.Builder(this);
rater.setTitle("This is the rating dialog");
}
@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;
}
public void showRatingDialog()
{
ratingBar = (RatingBar)findViewById(R.id.ratingStars);
rater.setNegativeButton("Abbrechen", null);
rater.setView(ratingBar);
rater.show();
}
}
我已經使用了的RatingBar靜態佈局嘗試,但我做到這一點,並試圖通過顯示一個警告對話框中的RatingBar時,沒有星星所示。下面是評價欄佈局文件:
<?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" >
<RatingBar
android:id="@+id/ratingStars"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="1"
/>
</LinearLayout>
嘗試將步長設置爲0.1 – Triode 2013-03-19 16:15:47