Androidアプリのアラートダイアログで評価バーを表示したい。私が直面している問題は、画面の幅によっては、評価バーに横向きモードで5つ以上の星(最大10個)が表示され、関数setNumStars()が効果を発揮しないことです。すでにこの問題を扱っている投稿がありますが、動的に作成している間、ラウトが静的に定義されているレーティングバーを扱っています。この問題を解決する方法は?
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();
}
}
評価バーに静的レイアウトを使用しようとしましたが、これを実行してアラートダイアログを介して評価バーを表示しようとすると、星が表示されません。評価バーのレイアウトファイルは次のとおりです。
<?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>