我的要求是打开一个允许用户对内容进行评分的对话框,该对话框中有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星,评级栏布局也不正确。任何帮助都是非常感谢的。谢谢!
发布于 2019-11-26 16:23:07
你可以这样尝试。Working for me用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>发布于 2019-11-26 16:27:19

尝尝这个,
<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。
发布于 2019-11-26 16:28:41
你已经给你的根LinearLayout指定了android:layout_width="300dp",这就是为什么它没有显示10星的原因。
要使其正常工作,您需要根据您的需求为其提供match_parent或wrap_content
https://stackoverflow.com/questions/59046122
复制相似问题