Android RatingBar соответствует ширине родительского элемента - PullRequest
0 голосов
/ 31 октября 2019

Я не понимаю, почему виджет Android RatingBar не масштабируется до ширины, указанной в макете.

Если у меня есть что-то простое, например

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".home.view.TempActivity">

    <androidx.cardview.widget.CardView
        android:id="@+id/cardView"
        android:layout_width="170dp"
        android:layout_height="220dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <androidx.appcompat.widget.AppCompatRatingBar
            android:id="@+id/ratingBar"
            style="?attr/ratingBarStyleIndicator"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:isIndicator="true"
            android:max="5"
            android:numStars="5" />
    </androidx.cardview.widget.CardView>

</androidx.constraintlayout.widget.ConstraintLayout>

Последняя звездаотрезать. Конечно, я мог бы использовать ratingBarStyleSmall вместо ratingBarStyleIndicator, но тогда он слишком мал. Как вы можете получить его, чтобы он просто масштабировался до ширины родительского элемента (в данном случае это CardView на 170dp)?

Ответы [ 2 ]

0 голосов
/ 31 октября 2019

Вы должны установить вид карты android:layout_width на wrap_content.

и изменить размер RatingBar Вы можете сделать это:

     <androidx.appcompat.widget.AppCompatRatingBar
        android:id="@+id/ratingBar"
        style="?attr/ratingBarStyleIndicator"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:isIndicator="true"
        android:max="5"
        android:numStars="5"
        android:transformPivotX="0dp"
        android:transformPivotY="0dp"
        android:scaleY="0.8"
        android:scaleX="0.8" />

Как можноУменьшить размер Рейтинга?

0 голосов
/ 31 октября 2019

Вы можете изменить ширину карты в качестве содержимого переноса.

...