问题
I am creating custom RatingBar using this property android:progressDrawable="@drawable/ratingstars"
When I apply this property, it automatically add some more space. So, I want to remove unnecessary space.
if I remove this property, I got the default RatingBar, so please, help me.
Here is the screenshot, so you can understand better.
Here is my xml file
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:elevation="20dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:orientation="vertical"
android:weightSum="10">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8"
android:background="@drawable/placeholder"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2">
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:layout_toLeftOf="@+id/rating"
android:maxLines="1"
android:text="Rides"
android:textColor="@color/colorPrimary"
android:textSize="20sp"
android:textStyle="bold" />
<RatingBar
android:id="@+id/rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:layout_toLeftOf="@+id/tv_more"
android:layout_toStartOf="@+id/tv_more"
android:isIndicator="true"
android:progressDrawable="@drawable/ratingstars"
android:rating="4" />
<TextView
android:id="@+id/tv_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/rounded"
android:padding="10dp"
android:text="More"
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
Custom drawable ratingstars.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:layout_gravity="center_vertical"
android:id="@android:id/background"
android:drawable="@drawable/star_blank" />
<item
android:layout_gravity="center_vertical"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:id="@android:id/secondaryProgress"
android:drawable="@drawable/star_blank" />
<item
android:layout_gravity="center_vertical"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:id="@android:id/progress"
android:drawable="@drawable/star_fill" />
</layer-list>
回答1:
Use Rating bar lib to customize all the ratingbar properties https://github.com/whinc/RatingBar
来源:https://stackoverflow.com/questions/40670998/ratingbar-layout-centervertical-property-not-work-after-set-progressdrawable