Android 的评级栏问题

发布于 2024-11-29 07:00:38 字数 2924 浏览 2 评论 0原文

我正在尝试自定义一些 Android 的评级栏。

我找到了一个 教程 来做到这一点,但我有一个问题。

我将评级栏 numStars 的属性设置为 5。

我得到的是,评级栏的每个“星星”将代表我的三个。

我在本教程的评论中读到,有人遇到了类似的问题,但该问题没有解决方案。

有人可以在 Android 2.2 上尝试这个教程吗?或者推荐另一个教程?

预先感谢您

UPD:

这是我的一些代码:

res/drawable/star_selector_full_filled.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/star_highlighted" />

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

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

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

</selector>

res/drawable/star_selector_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/star_white" />

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

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

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

</selector>

res/drawable/star_selector.xml:

<?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/star_selector_empty" />
    <item android:id="@+android:id/secondaryProgress"
          android:drawable="@drawable/star_selector_empty" />
    <item android:id="@+android:id/progress"
          android:drawable="@drawable/star_selector_full_filled" />
</layer-list>

res/values/styles.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="starRatingBar" parent="android:style/Widget.RatingBar">
        <item name="android:progressDrawable">@drawable/star_selector</item>
        <item name="android:minHeight">25dip</item>
        <item name="android:maxHeight">25dip</item>
    </style>    
</resources>

I'm trying to customize a bit the android's RatingBar.

I found a tutorial to do that, but I have a problem.

I set property of rating bar numStars to 5.

What I get, that every 'star' of rating bar will be represented of three of mine.

I read in comments to this tutorial, that somebody's got the similar problem, but there is no solution for that problem.

Can somebody try this tutorial on Android 2.2? Or recommend another tutorial?

Thank you in advance

UPD:

And here is a bit of my code:

res/drawable/star_selector_full_filled.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/star_highlighted" />

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

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

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

</selector>

res/drawable/star_selector_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/star_white" />

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

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

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

</selector>

res/drawable/star_selector.xml:

<?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/star_selector_empty" />
    <item android:id="@+android:id/secondaryProgress"
          android:drawable="@drawable/star_selector_empty" />
    <item android:id="@+android:id/progress"
          android:drawable="@drawable/star_selector_full_filled" />
</layer-list>

res/values/styles.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="starRatingBar" parent="android:style/Widget.RatingBar">
        <item name="android:progressDrawable">@drawable/star_selector</item>
        <item name="android:minHeight">25dip</item>
        <item name="android:maxHeight">25dip</item>
    </style>    
</resources>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何以笙箫默 2024-12-06 07:00:39

我遇到了同样的问题...它与您部署的最小版本和屏幕尺寸有关。

我解决了这个问题,在 android 清单中手动设置支持的屏幕尺寸:

<supports-screens android:smallScreens="true" 
      android:normalScreens="true" 
      android:largeScreens="true" 
      android:anyDensity="true" />

希望它有帮助。

编辑:

我实际上在这里回答了同样的问题。

您需要做的就是将布局宽度设置为wrap_content< /强>

I had the same problem... it has something to do with the min version you deploy to and the screen size.

I solved it manually setting the supported screen sizes in the android manifest:

<supports-screens android:smallScreens="true" 
      android:normalScreens="true" 
      android:largeScreens="true" 
      android:anyDensity="true" />

Hope it helps.

Edit:

I actually answered this same problem here.

All you need to do is set the layout width to wrap_content

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文