https://github.com/lnjky/fashion_people
GitHub - lnjky/fashion_people: 패션 추천 어플
패션 추천 어플. Contribute to lnjky/fashion_people development by creating an account on GitHub.
github.com
코드 전체를 보려면 위에 링크를 통해 확인할 수 있습니다.
RatingBar는 별 모양으로 평점이나 점수 를 매기는 위젯이다.
아래의 그림을 보면 딱 느낌이 올것이다.
우리가 흔히 아는 이런 모양의 별점을 주는 것이다.
이는 안드로이드에서 지원을 해주는데 이번 글에서는 이에 대해 작성해보려 한다.
우선 간단하게 XML에서 작성하는 주요 기능이다.
이렇게 4가지 속성에 대해 Rating Bar를 수정할 수 있다.
예시 코드를 보면 이렇다.
<RatingBar
android:id="@+id/upload_ratingbar"
style="@style/Widget.AppCompat.RatingBar.Indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:layout_marginBottom="4dp"
android:isIndicator="true"
android:max="5"
android:rating="0"
android:stepSize="0.5"
android:progressTint="#B388FF"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/tv_ratingbar"
app:layout_constraintHorizontal_bias="0.48"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/item_upload_contents">
</RatingBar>
해당 코드에서는 최대 별점을 5, 처음 표시될 별점을 0, 별 반칸당 0.5씩 수치가 올라간다.
isIndicator를 ture를 줘서 사용자가 드래그를 통해 별점을 줄 수 없게 했다.
Constraint Layout을 사용하였기 때문에 margin의 경우에는 상황에 맞게 조정해주면 된다.
Rating Bar에 대한 설명은 Android Developers에서도 확인할 수 있다.
https://developer.android.com/reference/android/widget/RatingBar
RatingBar | Android Developers
developer.android.com
'안드로이드' 카테고리의 다른 글
[안드로이드] 기상청 단기예보 API 사용하기 - 1 (0) | 2023.01.06 |
---|---|
[안드로이드] 댓글 작성 만들기 (0) | 2023.01.05 |
[안드로이드] 작성글 리사이클러뷰로 불러오기 (0) | 2023.01.05 |
[안드로이드] 파이어스토어 게시글 작성 만들기 (0) | 2023.01.05 |
[안드로이드] 파이어스토어의 데이터 가져오기 (0) | 2023.01.05 |