Проблема в уменьшении размера Рейтинга. - PullRequest
11 голосов
/ 30 июля 2011

Я хочу уменьшить размер строки рейтинга, у меня есть некоторые свойства стиля, которые делают это, но они недоступны для взаимодействия с пользователем, они просто Индикатор.Итак, пожалуйста, дайте мне знать, как уменьшить размер.Заранее спасибо.

Ответы [ 4 ]

26 голосов
/ 30 июля 2011

Как приклеить указанный код здесь ...

Шаг-1. Вам нужен собственный рейтинг звезд в res/drawable ...

A full star

Empty star

Шаг-2 В res/drawable вам нужно ratingstars.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/star_empty" />
    <item android:id="@+android:id/secondaryProgress"
          android:drawable="@drawable/star_empty" />
    <item android:id="@+android:id/progress"
          android:drawable="@drawable/star" />
</layer-list>

Шаг-3 В res/values вам нужно styles.xml, как следует ...

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="foodRatingBar" parent="@android:style/Widget.RatingBar">
        <item name="android:progressDrawable">@drawable/ratingstars</item>
        <item name="android:minHeight">22dip</item>
        <item name="android:maxHeight">22dip</item>
    </style>
</resources>

Шаг 4 В вашем макете ...

<RatingBar 
      android:id="@+id/rtbProductRating"
      android:layout_height="wrap_content"
      android:layout_width="wrap_content"
      android:numStars="5"
      android:rating="3.5"
      android:isIndicator="false"
      style="@style/foodRatingBar"    
/>  

Попробуйте занятие ....

package x.y;

import android.app.Activity;
import android.os.Bundle;

public class RatingBarDemo extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.product);

    }
}

С этим макетом product.xml ...

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingTop="5dip"
    android:paddingBottom="5dip">
    <ImageView
        android:id="@+id/imgProduct"
        android:layout_width="50dip"
        android:layout_height="50dip" 
        android:src="@drawable/icon" 
        android:scaleType="centerCrop"
        />
    <RelativeLayout
        android:id="@+id/layProductInfo"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/imgProduct"
        android:paddingLeft="5dip"
        android:paddingRight="0dip"
        android:paddingTop="5dip"
        android:paddingBottom="5dip">  
        <TextView
            android:id="@+id/tvProductName"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Product Name"
            android:textSize="17dip" 
            />
        <RatingBar 
            android:id="@+id/rtbProductRating"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:numStars="5"
            android:rating="3.5"
            android:isIndicator="false"
            style="@style/foodRatingBar"
            android:layout_below="@id/tvProductName"
            />  
        <TextView
            android:id="@+id/tvPriceLabel"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="$45.87"
            android:layout_toRightOf="@id/rtbProductRating"
            android:layout_below="@id/tvProductName"
            android:paddingLeft="10dip"
            android:textSize="17dip" 
            />  
      </RelativeLayout>     
  </RelativeLayout>
0 голосов
/ 27 января 2018

Рабочий код: Вы можете легко уменьшить размер звездочек Просто добавьте XML, как показано ниже

android: scaleX = "0.5" android: scaleY = "0.5"

  <RatingBar
            android:id="@+id/ratingBar_visibility"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:numStars="5"
            android:scaleX="0.5"
            android:scaleY="0.5" />
0 голосов
/ 02 марта 2017

Попробуйте изменить стиль

 <RatingBar
        android:layout_width="wrap_content"
        android:rating="4.5"
        style="@style/Base.Widget.AppCompat.RatingBar.Small"
        android:layout_height="wrap_content" />
0 голосов
/ 13 августа 2015

Я перебрал множество постов с тем же вопросом здесь и пробовал ответ, предоставленный @ Vaibhav A. Jani , когда я просто остановился на более простом решении этого вопроса.,Я не говорю, что @ Vaibhav A. Jani ответ неправильный, хотя.

Попробуйте, мне показалось, что звезды гораздо меньше:

RatingBar ratingBar = new RatingBar(context, null, android.R.attr.ratingBarStyleSmall);

А также я смог динамически создать множество RatingBar, не касаясь ни одного xml-файла, только кодирование Java.

Ссылка

...