>

WRAP_CONTENT 를 설정할 수 있습니다  내 레이아웃의 매개 변수에 있지만 CENTER 를 어떻게 설정합니까?  중력?

final AlertDialog.Builder popDialog = new AlertDialog.Builder(this);
    final RatingBar rating = new RatingBar(this);
    rating.setMax(5);
    rating.setRating(1);
    rating.setNumStars(5);
    popDialog.setIcon(android.R.drawable.btn_star_big_on);
    popDialog.setTitle("Vote!! ");
    popDialog.setView(rating);
    popDialog.setPositiveButton(android.R.string.ok,
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    int rawrating = rating.getProgress();
                    dialog.dismiss();
                }
            })
            .setNegativeButton("Cancel",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                        }
                    });
    popDialog.create();
    popDialog.show();
    // force to set setNumStars
    rating.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;

  • 답변 # 1

    이것이 도움이 될 것입니다.

    <강한>이

    와 같이 정의보기를 craete

    <LinearLayout 
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:gravity="center"
     android:orientation="vertical">
       <RatingBar
       android:id="@+id/ratingbar"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:max="5"
       android:numStars="5"
       android:stepSize="1" />
    </LinearLayout>
        final AlertDialog.Builder popDialog = new AlertDialog.Builder(MainActivity.this);
        popDialog.setIcon(android.R.drawable.btn_star_big_on);
        popDialog.setTitle("Vote!! ");
        popDialog.setView(R.layout.custom);
        popDialog.setCancelable(false);
        LayoutInflater mlLayoutInflater=LayoutInflater.from(MainActivity.this);
        final  View dialView=mlLayoutInflater.inflate(R.layout.custom,null);
        final RatingBar ratingBar = (RatingBar) dialView.findViewById(R.id.ratingbar);
        AlertDialog dialog_card = popDialog.create();
        Window window = dialog_card.getWindow();
        window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
        window.setGravity(Gravity.CENTER);
    
        popDialog.setPositiveButton(android.R.string.ok,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        int rawrating = ratingBar.getProgress();
                        Toast.makeText(MainActivity.this, "Rating :-> " + rawrating, Toast.LENGTH_SHORT).show();
                    }
                })
                .setNegativeButton("Cancel",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                            }
                        });
        popDialog.show();
    
    

  • 답변 # 2

    이걸 시도해보십시오 ...

           Window window = dialog_card.getWindow();
            window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
            window.setGravity(Gravity.CENTER);
    
    

  • 이전 excel - 현재 폴더의 파일을 반복하고 편집하는 VBA 스크립트
  • 다음 javascript - 다른 코드가 null이 아닌 경우 셀에 코드를 설정하는 방법 Google SpreadSheet