> aa > final AlertDialog.Builder popDialog = new AlertDialog.Builder(ExercisesActivity.this); final RatingBar rb = new RatingBar(ExercisesActivity.this); popDialog.setIcon(android.R.drawable.btn_star_big_on); rb.setMax(6); popDialog.setTitle("Set Difficulty"); popDialog.setView(rb); // Button OK popDialog.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //do things } }); popDialog.create(); popDialog.show();setMax()无效 最佳答案 如果您将RatingBar直接添加到AlertDialog中,那么它将导致有线输出,因为我们正在动态生成Ratingbar,而不是设置宽度。通过将LayoutParams设置为RatingBar并将RatingBar添加到LinearLayout并将LinearLayout视图添加到AlertDialog中,可以实现相同的效果。检查以下示例:final AlertDialog.Builder popDialog = new AlertDialog.Builder(getActivity());popDialog.setTitle("Set Difficulty");popDialog.setIcon(android.R.drawable.btn_star_big_on);LinearLayout linearLayout = new LinearLayout(ExercisesActivity.this);LinearLayout.LayoutParams lParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);final RatingBar rating = new RatingBar(ExercisesActivity.this);rating.setLayoutParams(lParams);rating.setNumStars(6);linearLayout.addView(rating);popDialog.setView(linearLayout);// Button OKpopDialog.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //do things } });popDialog.create();popDialog.show();输出:关于android - Android评分栏超出了对话框的范围,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55701386/ 10-11 23:03