Android中有10个星级的评分栏

问题描述 投票:0回答:2

我想打开一个对话框,允许用户对内容进行评分,并且该对话框中有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">

    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/text_rate"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/margin_20"
        android:layout_marginTop="@dimen/margin_30"
        android:text="@string/rate_this"
        android:textColor="#de000000"
        android:textSize="@dimen/margin_20"
        app:fontFamily="@font/muli_extra_bold" />

    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/text_movie_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/margin_20"
        android:layout_marginTop="@dimen/margin_7"
        android:text="BajiRao Mastani"
        android:textColor="#de000000"
        android:textSize="@dimen/margin_14"
        app:fontFamily="@font/muli_regular" />


    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/text_rating_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/margin_20"
        android:layout_marginTop="@dimen/margin_14"
        android:text="@string/your_rating"
        android:textColor="@color/color_orange"
        android:textSize="@dimen/margin_14"
        app:fontFamily="@font/muli_regular" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        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>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/margin_37"
        android:layout_marginEnd="@dimen/margin_10"
        android:gravity="right">

        <androidx.appcompat.widget.AppCompatTextView
            android:id="@+id/rank_dialog_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="@dimen/margin_10"
            android:text="@string/cancel"
            android:textColor="@color/tv_cancel_color_name"
            android:textSize="@dimen/margin_14"
            app:fontFamily="@font/muli_semi_bold" />

        <androidx.appcompat.widget.AppCompatTextView
            android:id="@+id/rank_dialog_button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/margin_15"
            android:layout_marginEnd="@dimen/margin_12"
            android:text="@string/rate"
            android:textColor="@color/tv_rate_color_name"
            android:textSize="@dimen/margin_14"
            app:fontFamily="@font/muli_extra_bold" />
    </LinearLayout>

</LinearLayout>

它仅显示9星,并且评级栏布局也不正确。请参考所附的屏幕截图。任何帮助表示赞赏。谢谢!!

screenshot of rating dialog

我想打开一个对话框,允许用户对内容进行评分,并且该对话框中有10个星标。我尝试了不同的方法,但是没有用。以下是我的rating_dialog.xml文件

android xml android-layout
2个回答
0
投票

您可以尝试这样。通过底部对话框enter image description here


0
投票

尝试一下,


0
投票

您已将android:layout_width="300dp"赋予根LinearLayout,这就是为什么它不显示第10星的原因。

© www.soinside.com 2019 - 2024. All rights reserved.