android中的10颗星评级栏

android中的10颗星评级栏,android,xml,android-layout,Android,Xml,Android Layout,我的要求是打开一个对话框,允许用户对内容进行评分,对话框中有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-aut

我的要求是打开一个对话框,允许用户对内容进行评分,对话框中有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颗星,评级栏的布局也不正确。感谢您的帮助。谢谢

你可以这样试试。为我工作用bottom打开

    <?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>

您可以这样尝试。为我工作用bottom打开

    <?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。

试试这个

   <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\u width=“300dp”
添加到根
线性布局中,这就是它没有显示第10颗星的原因


要使其正常工作,您需要根据您的要求为其提供
match\u parent
wrap\u内容

您已将
android:layout\u width=“300dp”
提供给根
LinearLayout
,这就是它没有显示第10颗星的原因

要使其正常工作,您需要根据您的要求为其提供
match\u parent
wrap\u content

我曾经使用过这个,您可以选择您想要的星星数量

解决方案:

Android不会调整分级栏中的星星大小。请使用分级栏中的自定义样式调整分级栏的大小

<style name="MyRatingBar" parent="@android:style/Widget.DeviceDefault.RatingBar.Indicator">
    <item name="android:minHeight">48dp</item>
    <item name="android:maxHeight">48dp</item>
</style>

48dp
48dp
然后将该样式添加到分级栏

<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"  />

解决方案:

Android不会调整分级栏中的星星大小。请使用分级栏中的自定义样式调整分级栏的大小

<style name="MyRatingBar" parent="@android:style/Widget.DeviceDefault.RatingBar.Indicator">
    <item name="android:minHeight">48dp</item>
    <item name="android:maxHeight">48dp</item>
</style>

48dp
48dp
然后将该样式添加到分级栏

<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"  />


谢谢兄弟!!!它起作用了,但你们能精确地为评级条提供起始和终止保证金吗?或者这会损害你的布局吗?我现在注意到它在我的评级对话框中只显示了9颗星。有什么建议吗?这是我更新的xml,当点击评级图像时,我会使用对话框对象显示它。这是你更新的xml。这是结果屏幕。检查这个谢谢兄弟!!!它起作用了,但你们能精确地为评级条提供起始和终止保证金吗?或者这会损害你的布局吗?我现在注意到它在我的评级对话框中只显示了9颗星。有什么建议吗?这是我更新的xml,当点击评级图像时,我会使用对话框对象显示它。这是你更新的xml。这是结果屏幕。检查这个请,检查我的答案请,检查我的答案我尝试了你的代码,但仍然没有显示第10颗星。我将scaleX和scaleY减少到.9仍然没有任何区别。我尝试了你的代码,但仍然没有显示第10颗星。我将scaleX和scaleY减少到了.9,但仍然没有任何区别。