android - 评分栏星级不变

标签 android android-layout ratingbar

在我的代码中,我想设置我的自定义星星,但它没有正常工作

 <RatingBar
                android:id="@+id/ratingBar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:numStars="5"
                android:stepSize="1"
                android:rating="1"
                android:progressDrawable="@drawable/rating_bar_color"/>

rating_bar_color.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background" android:drawable="@drawable/starw30" />
    <item android:id="@android:id/progress" android:drawable="@drawable/star" />
</layer-list>

我使用这段代码以及我得到的结果

enter image description here

线条来自哪里。星星的大小与默认星星大小相同。

最佳答案

出现这些行是因为您正尝试使用 android:layout_height="wrap_content" 包裹评分栏图像。因此,作为一种解决方案,您必须根据图像的大小提供评分栏的高度。

如果评分栏图像的大小是20,那么尝试添加

android:layout_height="20dip"

这对你有用!

关于android - 评分栏星级不变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20541169/

相关文章:

android - 为什么 FrameLayout 没有在我的布局中正确设置 Z 顺序?

android - RatingBar触摸位置不准确

Android RatingBar 在某些设备上显示黑色覆盖

android - RecyclerView 适配器显示错误的图像

android - 读取 NFC 标签时出现奇怪的字符

android - 在主要 Activity 上绘制 fragment

android - 以不同方式自定义 RatingBar 星星

android - 动画期间的 onClick on View 不起作用

android - RecyclerView View 中的 EditText 在键盘打开时分离

java - 改变 textView 的布局引力