Android 尽管将步骤设置为1,评级栏仍显示半星
我正在向自定义组件动态添加评级栏。我正在从服务器接收评级,最初显示为ok。但是,举例来说,如果我得到5颗星的评级,如果我点击第二颗星,那么3、4和5颗星的绘制方式就像是各得到半颗星,这对我来说毫无意义。如果我从服务器收到0颗星,修改工作正常,并且星星画得很完美,如果我从服务器收到2颗星,星星3、4和5工作正常,但是星星1和2的绘制就像收到半颗星一样 评级栏的XML如下所示:Android 尽管将步骤设置为1,评级栏仍显示半星,android,ratingbar,Android,Ratingbar,我正在向自定义组件动态添加评级栏。我正在从服务器接收评级,最初显示为ok。但是,举例来说,如果我得到5颗星的评级,如果我点击第二颗星,那么3、4和5颗星的绘制方式就像是各得到半颗星,这对我来说毫无意义。如果我从服务器收到0颗星,修改工作正常,并且星星画得很完美,如果我从服务器收到2颗星,星星3、4和5工作正常,但是星星1和2的绘制就像收到半颗星一样 评级栏的XML如下所示: <RatingBar android:layout_width="wrap_content" and
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ratingbar"
android:layout_alignParentEnd="true"
android:layout_below="@+id/eventsubtitle"
android:stepSize="1.0"
android:max="5"/>
有人能帮我吗?多谢各位
编辑:截图:
编辑2:布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/timein"
android:textSize="30sp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:layout_marginStart="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/timeout"
android:layout_alignStart="@+id/timein"
android:layout_below="@+id/timein"
android:textSize="30sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/eventtitle"
android:layout_toEndOf="@+id/timein"
android:layout_marginStart="40dp"
android:textStyle="bold"
android:textSize="18sp"
android:layout_marginTop="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/eventsubtitle"
android:layout_alignStart="@+id/eventtitle"
android:layout_below="@+id/eventtitle"
android:textSize="15sp"/>
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ratingbar"
android:layout_alignParentEnd="true"
android:layout_below="@+id/eventsubtitle"
android:stepSize="1.0"/>
<ImageView
android:layout_width="2dp"
android:layout_height="wrap_content"
android:id="@+id/verticalline"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:layout_toEndOf="@+id/timein"
android:layout_marginStart="20dp"
android:layout_alignBottom="@+id/speakerrl"
android:background="@color/colorPrimary"
android:layout_marginBottom="50dp"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/speakerrl"
android:layout_below="@+id/timeout"
android:layout_marginTop="30dp">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:id="@+id/imagen"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginStart="20dp"/>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@android:drawable/ic_menu_directions"
android:id="@+id/arrow"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/imagen"
android:layout_marginStart="60dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/speaker"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/arrow"
android:layout_marginStart="10dp"
android:textSize="18sp"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/speakersubtitle"
android:layout_alignStart="@+id/speaker"
android:layout_below="@+id/speaker"
android:textSize="15sp"/>
</RelativeLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/askbutton"
android:text="@string/askquestion"
android:layout_below="@+id/speakerrl"
android:layout_centerHorizontal="true"
android:background="@drawable/buttonshape"
android:layout_marginBottom="20dp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="@+id/askbutton"
android:background="@color/colorPrimary"/>
</RelativeLayout>
以编程方式添加最大额定值,应该可以解决此问题
ratingBar.setMax(5);
编辑:
将您的评级栏替换为并检查
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_alignParentEnd="true"
android:layout_below="@+id/eventsubtitle">
<RatingBar
android:layout_width="wrap_content"
android:layout_height="45dp"
android:id="@+id/ratingbar"
android:stepSize="1.0"/>
</LinearLayout>
没有区别,如果我从服务器收到5星评级,并将其修改为2星,例如,3星4星和5星看起来每个星都收到半星,如屏幕截图所示。你能添加完整布局吗?我正在将完整布局添加到问题中。这是一个添加到另一个布局内的线性布局中的布局,该布局被添加到一个ViewFlipper中…确定为分级栏添加另一个父级线性布局,并在其中保留除分级栏之外的任何内容,并且选中No运气,行为是相同的。很遗憾,我不得不寻找第三个分级栏库以使其正常工作。。。
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_alignParentEnd="true"
android:layout_below="@+id/eventsubtitle">
<RatingBar
android:layout_width="wrap_content"
android:layout_height="45dp"
android:id="@+id/ratingbar"
android:stepSize="1.0"/>
</LinearLayout>