2

我正在 android 中创建一个自定义的评分栏。RatingBar我的要求是即使图像的大小增加,我也希望星星的大小应该是布局兼容的。星星图像被隐藏了。这是我尝试过的 XML 代码

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:paddingBottom="@dimen/activity_vertical_margin"
             android:paddingLeft="@dimen/activity_horizontal_margin"
             android:paddingRight="@dimen/activity_horizontal_margin"
             android:paddingTop="@dimen/activity_vertical_margin"
             tools:context=".MainActivity" >
             <LinearLayout
             android:id="@+id/linear1"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:orientation="horizontal"
             android:background="#800080"
             android:layout_centerInParent="true"    
             android:width="180dp"
             android:height="180dp"
             >   
               <RatingBar
                   android:id="@+id/rateCheck"
                   android:background="#008000"
                   style="@style/CustomRatingBar"
                   android:layout_width="100dp"
                   android:layout_height="50dp"
                   android:layout_alignParentTop="true"
                   android:layout_centerHorizontal="true"
                   android:layout_marginTop="182dp"
                   android:max="5"
                   android:rating="5"
                   android:stepSize="1"
                   android:numStars="5"/>
            </LinearLayout>
            </RelativeLayout>

并且样式如下@drawable/custom_ratingbar 16dip 16dip customratingbar.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/custom_ratingbar_empty" />
    <item android:id="@+android:id/secondaryProgress"
android:drawable="@drawable/custom_ratingbar_empty" />
    <item android:id="@+android:id/progress"
android:drawable="@drawable/custom_ratingbar_filled" />
</layer-list>

自定义 ratingbarempty

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="@drawable/star_off" />

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

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

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

</selector>

customratingbarfilled

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="@drawable/star_on" />

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

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

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

</selector>
4

0 回答 0