programing

별 다섯 개를 보여주는 Rating Bar를 만드는 방법

css3 2023. 9. 27. 18:06

별 다섯 개를 보여주는 Rating Bar를 만드는 방법

나는 a를 추가하는 방법의 표준 예시를 따르고 있습니다.RatingBar. 내가 사용하려고 했던 별의 수를 조절하는 것.android:numStars="5". 문제는 별의 숫자가 전혀 효과가 없어 보인다는 것입니다.초상화 배치에서는 별 6개가 나오고 휴대폰을 뒤집으면 별 10개 정도가 나옵니다.활동의 별 수를 설정하려고 했습니다(myBar.setNumStars(5)xml을 로드하지만 해당 옵션도 성공하지 못했습니다.

그래서 제 질문은 별 다섯 개만 보여주도록 배치를 어떻게 정의할 것인가 하는 것입니다.numStars효과가 없는 것 같습니다.

<RatingBar
            android:id="@+id/rating"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="?android:attr/ratingBarStyleSmall"
            android:numStars="5"
            android:stepSize="0.1"
            android:isIndicator="true" />

암호로

mRatingBar.setRating(int)

RatingBar.setNumStar문서에는 다음과 같이 나와 있습니다.

표시할 별 개수를 설정합니다.이러한 내용이 제대로 표시되도록 하려면 위젯 랩 내용의 레이아웃 폭을 지정하는 것이 좋습니다.

레이아웃 폭을 다음과 같이 설정합니다.wrap_content이 문제를 해결해야 합니다.

효과가 있었습니다.RatingBar안에 있어야 함LinearLayout내용을 랩핑할 레이아웃 너비를 설정하는 것 외에RatingBar.

추가적으로, 만약 당신이 a를 설정한다면layout_weight, 이것이 대신합니다.numStars기여하다.

사용하시는 경우

android:layout_width="match_parent"

wrap_content를 사용하면 set numStars만 표시됩니다 :)

android:layout_width="wrap_content"

당신은 그냥 사용해야 합니다.numStars="5"사용자의 XML 및 세트에android:layout_width="wrap_content".
그러면 스타일 등을 가지고 놀 수 있지만 layout_width의 "wrap_content"가 효과적입니다.

<RatingBar
                    android:id="@+id/ratingBar"
                    style="@style/custom_rating_bar"
                    android:layout_width="wrap_content"
                    android:layout_height="35dp"
                    android:clickable="true"
                    android:numStars="5" 
                    />

XML 파일의 별 개수 구성...스타일이나 활동/조각 등으로 제공할 필요가 없습니다.중요: WIDTH를 랩 내용과 가중치가 사용되지 않도록 설정해야 합니다.

저는 별이 명시된 것보다 별을 초과한다는 문제에도 직면해 있습니다.이를 위해 상대적인 레이아웃이나 선형 레이아웃 중 어떤 레이아웃 유형이든 걱정하지 않습니다.다음과 같이 폭을 간단히 사용합니다.

ratingBar.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));


등급 표시줄에는 match_parentfill_parent를 사용하지 마십시오.
그 일들이 도움이 되길 바랍니다.

포장하시는 분들은.RatingBarA안에ConstraintLayout와 함께match_constraint편집기의 너비에 대해 편집기 미리보기는 실제 너비에 비례하는 별들의 수를 보여줄 것입니다, 만약 당신이 설정한다면.android:numStars속성. 사용wrap_content미리 보기를 정확하게 표시합니다.

<RatingBar android:id="@+id/myRatingBar"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_marginStart="48dp"
           android:layout_marginEnd="48dp"
           android:numStars="5"
           app:layout_constraintEnd_toEndOf="parent"
           app:layout_constraintStart_toStartOf="parent"
           app:layout_constraintTop_toBottomOf="parent" />

@Rolland라는 문제에 직면했을 때에도, 나는 다음과 같은 속성을 하나 더 포함시켰습니다.

android:layout_alignParentRight="true" 

내 안에RatingBarXML로 된 선언. 이 속성은 필요한 별들의 설정과 설정을 방해했습니다.NumStars

발견된 문제에 대해 계속해서 게시하세요!

저는 패딩을 벗기기 전까지 고민이 있었습니다.특정 기기에 보기 크기를 변경하지 않고 패딩에 맞게 내용을 압축하는 버그가 있는 것 같습니다.

한다를 합니다.padding,사용하다layout_margin대신.

간단한 별 등급을 둥근 그림으로 표시하려면 이 코드를 사용합니다.

public static String getIntToStar(int starCount) {
        String fillStar = "\u2605";
        String blankStar = "\u2606";
        String star = "";

        for (int i = 0; i < starCount; i++) {
            star = star.concat(" " + fillStar);
        }
        for (int j = (5 - starCount); j > 0; j--) {
            star = star.concat(" " + blankStar);
        }
        return star;
    }

이렇게 해서 이렇게.

button.setText(getIntToStar(4));

xml 레이아웃 안에 별 다섯 개의 기본 등급을 추가할 수 있습니다.

android:rating="5"

편집:

<RatingBar
        android:id="@+id/rb_vvm"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginBottom="@dimen/space2"
        android:layout_marginTop="@dimen/space1"
        style="@style/RatingBar"
        android:numStars="5"
        android:stepSize="1"
        android:rating="5" />

기본값은 xml 레이아웃에서 andoid:rating으로 설정됩니다.

<LinearLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <RatingBar
        android:id="@+id/ruleRatingBar"
        android:isIndicator="true"
        android:numStars="5"
        android:stepSize="0.5"
        style="?android:attr/ratingBarStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
</LinearLayout>

나는 그것을 발견했습니다.RatingBar되었습니다와 되어 있기 별 되었습니다.android:stretchColumns = "*".

내가 가져간 적이 있습니다.stretchCoulumns에서,RatingBar에 따라 android:numStars

목록 보기의 어댑터에서 등급을 사용하는 경우도 있습니다.

View android.view.LayoutInflater.inflate(int resource, ViewGroup root, boolean attachToRoot)

모든 특성이 제대로 작동하려면 다음 매개 변수가 필요합니다.

  1. 을 설정합니다.
  2. 부울라로

Ex: view = inflater.inflate(R.layout.m) 변환yId, 부모, false);

에 있는 실제적인 은 입니다를 입니다.wrap_contentmatch_parent. 를 .match_parent레이아웃은 numStars 변수보다 큰 경우에도 별로 채워집니다.

언급URL : https://stackoverflow.com/questions/3858600/how-to-make-ratingbar-to-show-five-stars