Android drawing.xml与位图大小不匹配

时间:2013-08-03 20:45:21

标签: android layout

我正在尝试创建一个大小与我的位图文件匹配的绘图xml。我得到了各种奇怪的结果。我的图纸文件名为rr.xml

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <solid android:color="#ff0000"/>
    <corners android:radius="4px" />
    <size android:height="64px" android:width="64px"/>
</shape>

我正在比较的位图是64px x 64px位图:

three flags

布局文件如下所示:

<?xml version="1.0" encoding="utf-8"?>

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

<ImageView

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/btnList"
        android:src="@drawable/three_flags_route"
        android:layout_gravity="center"
        />

<ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/btnStatus"
        android:src="@drawable/rr"
        android:layout_gravity="center"
        android:scaleType="center"
        />

</LinearLayout>

我希望红色方块与带有标志的图标大小相同。相反,我得到了这个(从模拟器屏幕截图中删除):

screenshot

几乎是它的1.5倍!任何想法我应该如何指定xml中的尺寸以使它们匹配?

1 个答案:

答案 0 :(得分:0)

来自docs

  

注意:形状缩放到容器视图的比例大小   默认情况下,此处定义的维度。当你使用形状时   在ImageView中,您可以通过设置来限制缩放   android:scaleType为“center”。