简体   繁体   English

Android RatingBar带有阴影/发光的星星

[英]Android RatingBar stars with shadow/glow

I want to add a shadow to the stars in a RatingBar. 我想为RatingBar中的星星添加阴影。 I also want to use half-stars, so I can't just add the shadow directly on the star image. 我也想使用半星,所以我不能只在星像上直接添加阴影。 Is this possible to achieve or will I have to create a custom RatingBar? 这是否有可能实现,还是我必须创建一个自定义的RatingBar?

I make non-filled stars transparent using the following drawable: 我使用以下可绘制对象使未填充的星星透明:

<?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="@android:color/transparent" />
    <item android:id="@android:id/secondaryProgress"
        android:drawable="@android:color/transparent" />
    <item android:id="@android:id/progress"
        android:drawable="@drawable/star" />
</layer-list>

Try to use another rating bar behind the original one and make its style as an shadow. 尝试在原始评级栏后面使用另一个评级栏,并将其样式设置为阴影。 Then sync the behind rating bar with the one in top. 然后将后面的评分栏与顶部的评分栏同步。

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignLeft="@+id/textView1"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="22dp" >

<RatingBar
    android:id="@+id/ratingBar2"
    android:layout_width="wrap_content"
    android:layout_height="40dp"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="0dp"
    android:layout_marginLeft="5dp"
    android:stepSize="0.5"
    android:focusable="false" />

<RatingBar
    android:id="@+id/ratingBar1"
    android:layout_width="wrap_content"
    android:layout_height="40dp"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="10dp"
    android:stepSize="0.5"
     />

</RelativeLayout>

then sync the the rating bars. 然后同步评分栏。 As any one changed the other will change too. 由于任何一个改变,另一个也会改变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM