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

问题描述

限时删除!!

我知道这听起来很麻烦,但是有时候感觉就像Android的UI组件和行为是不可能的.

I know this is going to sound ranty, but it just feels like Android's UI components and behaviours are off the wall sometimes.

考虑以下XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

    <RatingBar
    android:id="@+id/ratingBar1"
    android:style="@android:style/Widget.Holo.Light.RatingBar.Small"
    android:progress="3"
    android:max="5"
    android:numStars = "5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />


</LinearLayout>

在不同设备尺寸下的外观截图

Screenshots of how that would look on different device sizes:

Nexus S等级栏

Nexus S rating bar

平板电脑评分栏

小型设备分级栏

即使仅在预览工具中,我也可以确认它实际上是在设备上的外观.

Even though it's only in the preview tool, I can confirm that's actually how it looks on the devices.

小型设备的行为令人发疯.指定5个星星的RatingBar如何显示3个,为什么不按比例缩小星星以适合窗口?

The small device behaviour is maddening. How does a RatingBar that specifies 5 stars only get 3 displayed, why not scale down the stars to fit in the window?

考虑到wrap_content的宽度是问题,我切换到layout_width ="fill_parent"并没有改变小型设备的外观,但在Tablets上却完全搞砸了("numStars"为5)

Thinking the wrap_content width was the issue, I switched to layout_width="fill_parent" and that didn't change the look on a small device, but it completely messed up on Tablets (so much for "numStars" of 5):

我的问题是,有没有一种方法可以使RatingBar的大小正确?您会认为numStars或max足够了,但这完全是任意的.拉伸RatingBar以便绘制更多星星时,它会添加星星并查看进度为3时如何根据显示的星星数绘制它?不遵守numStars是没有道理的!

My question is, is there a way to get proper behaviour for the RatingBar in terms of sizing? You would think the numStars or max would be sufficient but it's completely arbitrary. When the RatingBar is stretched so that it draws more stars, it adds stars and see how with a progress of 3, it draws it according to the number of stars displayed? It doesn't make sense not to adhere to numStars!

如果无法从RatingBar获得逻辑性能,是否还有其他选择,包括3rd party小部件?如果没有,我想我总是可以绘制5个ImageView并对其进行装配以相应地执行.

If there is no way to get logical performance from the RatingBar, are there any alternatives including 3rd party widgets? If not, I guess I could always draw 5 ImageViews and just rig it to perform accordingly.

(请记住,所有这些行为都是在布局中仅使用一个RatingBar来展示的-忘记尝试与其他小部件/组件一起调整大小,或者利用您自己的样式.我知道已经完成了,但是为什么这是默认行为? )

(Keep in mind all this behaviour was exhibited with just one RatingBar in the layout - forget trying to size with other widgets/components, or utilizing your own styles. I know it's been done, but why is this the default behavior?)

推荐答案

使用股票RatingBar时,我的感觉与您相同,所以我做了自己的事情: SimpleRatingBar .

I felt the same way as you when using the stock RatingBar, so I made my own: SimpleRatingBar.

它具有以下特点:

  • 完全正常工作android:layout_width:可以将其设置为wrap_contentmatch_parent或无菌dp.
  • 任意数量的星星.
  • 任意步长.
  • 可以完全控制星星大小,也可以设置最大大小.
  • 可自定义的颜色(边框,星星的填充和背景).
  • 可自定义的星际大小分隔.
  • 可自定义的星星边框宽度.
  • 允许设置OnRatingBarChangeListener
  • 可以将星星填充设置为从左到右或从右到左开始(RTL语言支持).
  • 集成在视图中的AnimationBuilder可通过动画以编程方式设置评分.
  • Fully working android:layout_width: it can be set to wrap_content, match_parent or abritary dp.
  • Arbitrary number of stars.
  • Arbitrary step size.
  • Size of stars can be controlled exactly or by setting a maximum size.
  • Customizable colors (border, fill and background of stars).
  • Customizable size separation between stars.
  • Customizable border width of stars.
  • Allows to set OnRatingBarChangeListener
  • Stars fill can be set to start from left to right or from right to left (RTL language support).
  • AnimationBuilder integrated in the view to set rating programatically with animation.

此处是其预览.

您可以在jcenterMaven Central中找到它.因此,在您的build.gradle文件中,只需添加您的依赖项即可:

You can find it either in jcenter or in Maven Central. So in your build.gradle file just add to your dependencies:

compile 'com.iarcuschin:simpleratingbar:0.1.+'

我希望它有用.

这篇关于Android RatingBar-完全混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 17:43