2

我想知道有人能帮助我吗?在不同的屏幕密度上显示时,我在使用自定义 RatingBar 时遇到了缩放问题。我已经建立了一个快速示例项目来解释我的问题。这只是一个非常基本的项目,目前只关注大屏幕尺寸,无论密度如何项目文件夹结构

正如您从图像中看到的那样,我有用于 RatingBar 的选择器,然后我在每个大密度可绘制文件夹中都有两个单独的 RatingBars 的默认和完整图像(目前所有图像的大小相同)。为了显示这个自定义 RatingBar。我试图让这些 RatingBars 正确显示,并尝试了两种不同的方法,如下所述。第一种方法我尝试在布局文件中指定 RatingBars 的宽度和高度,如下图所示:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RatingBar 
        android:id="@+id/rb_test_1"           
        android:numStars="1"
        android:rating="0.5"
        android:stepSize="0.01"
        android:isIndicator="true"
        android:layout_width="150dp"
        android:layout_height="111dp"
        android:layout_gravity="bottom"
        android:gravity="bottom"                                                          
        android:progressDrawable="@drawable/selector_rb_test_1" />

    <RatingBar 
        android:id="@+id/rb_test_2"           
        android:numStars="1"
        android:rating="0.5"
        android:stepSize="0.01"
        android:isIndicator="true"
        android:layout_width="200dp"
        android:layout_height="154dp"
        android:layout_gravity="bottom"
        android:gravity="bottom"                                                          
        android:progressDrawable="@drawable/selector_rb_test_2" />

</LinearLayout>

查看 GUI 图形布局时,这会在基本 10.1 屏幕尺寸与 Nexus 10 上产生以下输出。它似乎在复制和拉伸图像。

TestScaling-10Inch Screens-SpecifyingSize

现在,当我尝试第二种方式时,这更像是我想要的方式(不必指定每个 RatingBars 的确切大小,只需将布局宽度和高度设置为换行,以下是代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RatingBar 
        android:id="@+id/rb_test_1"           
        android:numStars="1"
        android:rating="0.5"
        android:stepSize="0.01"
        android:isIndicator="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:gravity="bottom"                                                          
        android:progressDrawable="@drawable/selector_rb_test_1" />

    <RatingBar 
        android:id="@+id/rb_test_2"           
        android:numStars="1"
        android:rating="0.5"
        android:stepSize="0.01"
        android:isIndicator="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:gravity="bottom"                                                          
        android:progressDrawable="@drawable/selector_rb_test_2" />

</LinearLayout>

查看 GUI 图形布局时,这会在基本 10.1 屏幕尺寸与 Nexus 10 上产生以下输出。这会切断 RatingBar 图像的底部。

TestScaling-10Inch Screens-WrappingContent

无论屏幕的密度如何,我都希望能够毫无问题地显示多个 RatingBar。谁能帮我弄清楚为什么它在 Nexus10 屏幕上显示不同以及如何修复它?我已经坚持了一段时间了,如果有人能够阐明这一点,我将非常感激。非常感谢您提前。

4

1 回答 1

0

在上面的@Xavers 评论之后,这个问题是由于图像的缩放不正确。解决方案是遵循比例,如以下答案所示 - https://stackoverflow.com/a/11581786/1634369

ldpi | mdpi | tvdpi | hdpi | xhdpi | xxhdpi | xxxhdpi
0.75 | 1    | 1.33  | 1.5  | 2     | 3      | 4

感谢您的帮助@Xaver

于 2014-05-14T19:30:39.300 回答