与Android的的RatingBar问题 [英] Problems with Android's RatingBar

查看:96
本文介绍了与Android的的RatingBar问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想定制了一下Android的的RatingBar。

我发现了一个教程要做到这一点,但我有一个问题。

我设置的等级吧numStars属性为5。

我所得到的,即评级棒每一个明星将重新三级防雷的presented。

我看了评论本教程中,某人的得到了类似的问题,但对于这个问题没有解决方案。

有人可以尝试在Android 2.2本教程?或者推荐另一教程?

感谢你在前进

UPD:

这里是一个有点我的code:

RES /绘制/ star_selector_full_filled.xml:

 < XML版本=1.0编码=UTF-8&GT?;
<选择
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>

    <项目的android:STATE_ pressed =真
          机器人:state_window_focused =真
          机器人:可绘制=@可绘制/ star_highlighted/>

    <项目安卓state_focused =真
          机器人:state_window_focused =真
          机器人:可绘制=@可绘制/ star_highlighted/>

    <项目安卓state_selected =真
          机器人:state_window_focused =真
          机器人:可绘制=@可绘制/ star_highlighted/>

    <项目机器人:可绘制=@可绘制/ star_highlighted/>

< /选择器>
 

RES /绘制/ star_selector_empty.xml:

 < XML版本=1.0编码=UTF-8&GT?;
<选择
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>

    <项目的android:STATE_ pressed =真
          机器人:state_window_focused =真
          机器人:可绘制=@可绘制/ star_white/>

    <项目安卓state_focused =真
          机器人:state_window_focused =真
          机器人:可绘制=@可绘制/ star_white/>

    <项目安卓state_selected =真
          机器人:state_window_focused =真
          机器人:可绘制=@可绘制/ star_white/>

    <项目机器人:可绘制=@可绘制/ star_white/>

< /选择器>
 

RES /绘制/ star_selector.xml:

 < XML版本=1.0编码=UTF-8&GT?;
<层列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <项目机器人:ID =@ +安卓ID /背景
          机器人:可绘制=@可绘制/ star_selector_empty/>
    <项目机器人:ID =@ +安卓ID / secondaryProgress
          机器人:可绘制=@可绘制/ star_selector_empty/>
    <项目机器人:ID =@ +安卓ID /进步
          机器人:可绘制=@可绘制/ star_selector_full_filled/>
< /层列表>
 

RES /价值/ styles.xml:

 < XML版本=1.0编码=UTF-8&GT?;
<资源>
    <样式名称=starRatingBar父=机器人:款式/ Widget.RatingBar>
        <项目名称=机器人:progressDrawable> @可绘制/ star_selector< /项目>
        <项目名称=安卓了minHeight> 25dip< /项目>
        <项目名称=安卓了maxHeight> 25dip< /项目>
    < /风格>
< /资源>
 

解决方案

我有同样的问题......它是与最小版本部署到与屏幕尺寸。

我解决了手动设置支持的屏幕尺寸在Android清单:

 <支持屏安卓smallScreens =真
      机器人:normalScreens =真
      机器人:largeScreens =真
      机器人:anyDensity =真/>
 

希望它帮助。

修改

其实,我回答了这个相同的问题这里

所有你需要做的是设置布局宽度WRAP_CONTENT

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>

解决方案

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

这篇关于与Android的的RatingBar问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆