繁体   English   中英

Android RatingBar屏幕缩放问题

[英]Android RatingBar Screen Scaling Issue

我想知道有人能帮我吗。 在不同屏幕密度下显示时,使用自定义RatingBar时出现缩放问题。 我建立了一个快速示例项目来解释我的问题。 这只是一个非常基本的项目,目前只关心大屏幕尺寸,而不考虑密度 项目文件夹结构

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

<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-10英寸屏幕-SpecificationSize

现在,当我尝试第二种方法时,这更像是我想要的方法(不必指定每个RatingBar的确切大小,只需设置要包装的布局宽度和高度即可,以下是码:

<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-10英寸屏幕-包装内容

我想要做的就是不管屏幕的密度如何,都可以毫无问题地显示多个RatingBars。 谁能帮我弄清楚为什么Nexus10屏幕上的显示方式有所不同以及如何解决? 我已经坚持了好一阵子,如果有人能够阐明一点,我将非常感激。 提前非常感谢您。

在上述@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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM