[英]Rating Bar with 10 stars in android
我的要求是打开一个对话框,该对话框允许用户对内容进行评分,并且该对话框中有10个星。 我尝试了不同的方法,但是没有用。 以下是我的rating_dialog.xml
文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="300dp"
android:layout_height="match_parent"
android:background="@color/colorWhite"
android:orientation="vertical">
<RatingBar
android:id="@+id/dialog_rating_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/ratingBarStyleSmall"
android:layout_marginTop="@dimen/margin_15"
android:layout_gravity="center"
android:layout_marginEnd="@dimen/margin_30"
android:progressBackgroundTint="@color/colorHint"
android:progressTint="@color/color_orange"
android:secondaryProgressTint="@color/color_orange"
android:numStars="10"
android:scaleX="1.8"
android:scaleY="1.8" />
</LinearLayout>
它仅显示9星,并且评级栏布局也不正确。 任何帮助表示赞赏。 谢谢!!!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="62dp"
android:gravity="center_horizontal"
android:padding="@dimen/_10sdp"
android:text="@string/str_rate_this"
android:textSize="@dimen/_15sdp" />
<RatingBar
style="@style/Widget.AppCompat.RatingBar.Indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="10"
android:rating="5"
android:layout_gravity="center_horizontal"
android:isIndicator="false"
android:scaleX=".9"
android:scaleY=".9"
android:stepSize="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="@drawable/rectangle_background"
android:layout_margin="@dimen/_20sdp"
android:text="Rate now" />
</LinearLayout>
<RatingBar
android:id="@+id/dialog_rating_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/ratingBarStyleSmall"
android:layout_marginTop="@dimen/margin_15"
android:layout_gravity="center"
android:layout_marginEnd="@dimen/margin_30"
android:layout_marginStart="@dimen/margin_30"
android:progressBackgroundTint="@color/colorHint"
android:progressTint="@color/color_orange"
android:secondaryProgressTint="@color/color_orange"
android:numStars="10"
android:scaleX="1.8"
android:scaleY="1.2" />
为了适应星星,我将scaleY减小到1.2。
您已将android:layout_width="300dp"
赋予根目录LinearLayout
,这就是为什么它不显示第10星的原因。
要使其正常工作,您需要根据需要为其指定match_parent
或wrap_content
我曾经用过这个图书馆 ,你可以选择想要的星星数量
解:
Android不会调整RatingBar中的星星大小。请在评分栏中使用自定义样式来调整评分栏的大小。
<style name="MyRatingBar" parent="@android:style/Widget.DeviceDefault.RatingBar.Indicator">
<item name="android:minHeight">48dp</item>
<item name="android:maxHeight">48dp</item>
</style>
然后将该样式添加到评分栏
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="10"
android:stepSize="1.0"
android:max="10"
style="@style/MyRatingBar" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.