首页 > 解决方案 > 评级明星从最后开始削减

问题描述

我已经实现了 android 原生评级栏,但是当我将星数设置为 10 时,它会从屏幕末端切断它在某些设备上发生的情况,谁能帮助我如何设法在所有移动设备上始终显示 10 星?

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_marginBottom="@dimen/_15sdp"
android:layout_width="match_parent"
android:layout_height="wrap_content">


<TextView
    android:id="@+id/tValueLabel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="@dimen/_5sdp"
    android:textSize="@dimen/_11ssp" />



<RatingBar
    android:id="@+id/ratingBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    style="?android:attr/ratingBarStyleIndicator"
    android:isIndicator="false"
    android:layout_marginTop="@dimen/_5sdp"
    android:stepSize="1.0" />


</LinearLayout>

标签: androidandroid-layoutscreen-resolutionratingbar

解决方案


由于屏幕上没有空间容纳 10 颗星,您的 RatingBar 正在从头开始切割。解决方法是减小星的大小。没有直接的方法可以减小星的大小。在您的情况下, scaleX 和 scaleY 将起作用。请为 RatingBar 使用以下代码

<RatingBar
    android:id="@+id/ratingBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    style="?android:attr/ratingBarStyleIndicator"
    android:isIndicator="false"
    android:scaleX=".8"
    android:scaleY=".8"
    android:translationX="-10dp"
    android:layout_marginTop="5dp"
    android:stepSize="1.0" />

推荐阅读