Android 带有自定义图像的分级栏

Android 带有自定义图像的分级栏,android,android-view,android-custom-view,Android,Android View,Android Custom View,可以创建这样的自定义分级栏吗? 如果是的话,你能给我一个如何做的例子吗 提前谢谢 编辑:这不是一个合适的答案,因为OP希望自定义分级栏。但这仍然是一个解决方案 这是可能的。您只需将五个图像资源中的每一个都放在项目中,然后制作如下布局: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:

可以创建这样的自定义分级栏吗? 如果是的话,你能给我一个如何做的例子吗


提前谢谢

编辑:这不是一个合适的答案,因为OP希望自定义分级栏。但这仍然是一个解决方案

这是可能的。您只需将五个图像资源中的每一个都放在项目中,然后制作如下布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="60dp"
android:layout_height="match_parent"
android:background="@android:color/black"
android:gravity="left"
android:orientation="vertical"
android:weightSum="5" >

<ImageView
    android:id="@+id/oneStar"
    android:layout_width="50dp"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:src="@drawable/ic_launcher" />

<ImageView
    android:id="@+id/twoStars"
    android:layout_width="50dp"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:src="@drawable/ic_launcher"
    android:visibility="visible" />

<ImageView
    android:id="@+id/threeStars"
    android:layout_width="50dp"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:src="@drawable/ic_launcher"
    android:visibility="visible" />

<ImageView
    android:id="@+id/fourStars"
    android:layout_width="50dp"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:src="@drawable/ic_launcher"
    android:visibility="visible" />

<ImageView
    android:id="@+id/fiveStars"
    android:layout_width="50dp"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:src="@drawable/ic_launcher"
    android:visibility="visible" />

将您的资源作为ImageView的源。这应该是你的一个开始:D

很棒的教程

我将复制在这个答案的重要部分,以防链接将是无效的

首先,您应该创建一个扩展原始分级栏的样式

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="foodRatingBar" parent="@android:style/Widget.RatingBar">
        <item name="android:progressDrawable">@drawable/food_ratingbar_full</item>
        <item name="android:minHeight">48dip</item>
        <item name="android:maxHeight">48dip</item>
    </style>
</resources>
我只对所有州使用一个图像(实际上看起来很不错), 但是从选择器中可以看到,有四种不同的状态 可能(@drawable/cookie最终是一个实际的cookie png图像)。 这里最酷的是RatingBar组件会自动 当需要时,仅根据“满”和“满”填充部分cookie “空”图像(如果您支持一半评级,如我的示例图像)

然后,要使用样式,只需在RatingBar XML中添加样式属性

style="@style/foodRatingBar
要点是:如果需要,应该创建自定义样式


然后你可以用它来旋转

设置视图围绕轴心点旋转的角度。增加值会导致顺时针旋转


您希望自定义分级栏在布局中的什么位置?在对话框中,但这并不重要。我正在考虑这个问题,但我也希望分级栏可以根据我的需要进行自定义。无论如何,谢谢你。这不是正确的方法。您应该使用只显示5幅图像的
RatingBar
,与RatingBar没有任何共同之处!我读过这本图坦卡门,但它不允许我使用1/5系统。因为它可能只使用1或2个图像,1代表完整图像,2代表一半图像。但我需要使用1/5系统,例如5取3,等等
style="@style/foodRatingBar