Android RatingBar屏幕缩放问题

时间:2014-05-02 21:49:37

标签: android scaling screen-size ratingbar

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

从图像中可以看出,我有用于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

我想要做的就是无论屏幕的密度如何,都可以毫无问题地显示多个RatingBars。任何人都可以帮我弄清楚为什么它在Nexus10屏幕上显示不同以及如何修复它?我现在已经坚持了一段时间,如果有人能够解决这个问题,我会非常感激。非常感谢你提前。

1 个答案:

答案 0 :(得分: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