Java 自定义分级条可拉丝未正确重叠

Java 自定义分级条可拉丝未正确重叠,java,android,ratingbar,Java,Android,Ratingbar,我正在创建自定义分级栏。问题是,可绘制图像没有正确覆盖,因为有两个不同的图像具有相同的高度和宽度。当进度将被更新时,应该是这样的。默认图像应替换为image2。有什么想法吗 <RatingBar android:layout_weight="1" android:numStars="5" android:stepSize="1" android:progressDrawable="@drawable/customselecto

我正在创建自定义分级栏。问题是,可绘制图像没有正确覆盖,因为有两个不同的图像具有相同的高度和宽度。当进度将被更新时,应该是这样的。默认图像应替换为image2。有什么想法吗

<RatingBar
        android:layout_weight="1"
        android:numStars="5"
        android:stepSize="1"
        android:progressDrawable="@drawable/customselector"
        android:layout_width="wrap_content"
        android:layout_height="0dp"/>

这是我的自定义选择器

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background"
        android:drawable="@drawable/image1" />

    <item android:id="@android:id/secondaryProgress"
        android:drawable="@drawable/image1" />

    <item android:id="@android:id/progress"
        android:drawable="@drawable/image2" />

</layer-list>


我将选择器设置为分级栏的方式有点不同,但我不知道这是否有帮助:

<RatingBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/ratingBar"
    android:rating="3"
    android:numStars="5"
    android:stepSize="1"
    android:isIndicator="false"
    style="@style/mileageRatingBar"/>

在values/styles.xml文件中,输入以下内容:

<style name="mileageRatingBar" parent="@android:style/Widget.RatingBar">
    <item name="android:progressDrawable">@drawable/rating_stars</item>
    <item name="android:minHeight">32dip</item>
    <item name="android:maxHeight">32dip</item>
</style>

@可拉拔/额定值
32dip
32dip

你当然可以改变尺寸。正如您所看到的,这里是对自定义绘图的引用。

我将选择器设置为比率栏的方式有点不同,但我不知道它是否有帮助:

<RatingBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/ratingBar"
    android:rating="3"
    android:numStars="5"
    android:stepSize="1"
    android:isIndicator="false"
    style="@style/mileageRatingBar"/>

在values/styles.xml文件中,输入以下内容:

<style name="mileageRatingBar" parent="@android:style/Widget.RatingBar">
    <item name="android:progressDrawable">@drawable/rating_stars</item>
    <item name="android:minHeight">32dip</item>
    <item name="android:maxHeight">32dip</item>
</style>

@可拉拔/额定值
32dip
32dip
你当然可以改变尺寸。正如您所看到的,这里是对自定义可绘图的引用。

删除

 android:progressDrawable="@drawable/customselector" 
并在values/styles.xml中添加样式

像这样

<RatingBar
        android:layout_weight="1"
        android:numStars="5"
        android:stepSize="1"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
       style="@style/customRatingBar"/>
确保正确写入了项目id,然后您有两个选项可以将可绘制的指定为图像,或者使用自定义设置将选择器放入可绘制文件夹selector.xml中

代替image1putratingbar\u empty.xml

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true"
        android:state_window_focused="true"
        android:drawable="@drawable/image1" />

    <item android:state_focused="true"
        android:state_window_focused="true"
        android:drawable="@drawable/image1" />

    <item android:state_selected="true"
        android:state_window_focused="true"
        android:drawable="@drawable/image1" />

    <item android:drawable="@drawable/image1" />

</selector>

进行相同操作,但将选择器更改为image2

删除

 android:progressDrawable="@drawable/customselector" 
并在values/styles.xml中添加样式

像这样

<RatingBar
        android:layout_weight="1"
        android:numStars="5"
        android:stepSize="1"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
       style="@style/customRatingBar"/>
确保正确写入了项目id,然后您有两个选项可以将可绘制的指定为图像,或者使用自定义设置将选择器放入可绘制文件夹selector.xml中

代替image1putratingbar\u empty.xml

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true"
        android:state_window_focused="true"
        android:drawable="@drawable/image1" />

    <item android:state_focused="true"
        android:state_window_focused="true"
        android:drawable="@drawable/image1" />

    <item android:state_selected="true"
        android:state_window_focused="true"
        android:drawable="@drawable/image1" />

    <item android:drawable="@drawable/image1" />

</selector>



同样可以继续,但将选择器更改为image2

是否有理由拒绝投票?您好,您可以显示屏幕截图吗?@Sheychan编辑了这个问题。该死的,我想尝试一下,很遗憾我正在更新我的AS。我的网速比海胆还慢。你已经看到这个了吗@Sheychan.是的,我试过了,但对我的案子没有帮助任何反对投票的理由?嗨,你能给我一个截图吗?@Sheychan编辑了这个问题。该死的,我想尝试一下,很不幸我正在更新我的AS。我的网速比海胆还慢。你已经看到这个了吗@Sheychan.是的,我试过了,但对我的情况没有帮助什么是
Milgabar
?这是您的选择器文件的名称。编辑检查此答案image1和image2的尺寸是多少?第二次尝试使高度相等包装内容是什么
MilaqueatingBar
?这是选择器文件的名称。编辑检查此答案image1和image2的大小是多少?第二次尝试使高度相等包装内容如何使用selector.xml文件?如何使用selector.xml文件?