Android drawing.xml与位图大小不匹配
我正在尝试创建一个与位图文件大小匹配的图形xml。我得到了各种奇怪的结果。我的图形文件名为Android drawing.xml与位图大小不匹配,android,layout,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"/> <c
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位图:
布局文件如下所示:
<?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>
我希望红场的大小与带有旗帜的图标的大小相同。相反,我得到了这个(从emulator屏幕截图中截取):
它几乎是原来的1.5倍大!我该如何在xml中指定维度以使它们匹配?您有什么想法吗?来源:
注意:形状比例与容器视图的大小成比例
默认情况下,设置为此处定义的尺寸。在中使用形状时
对于ImageView,可以通过设置
android:scaleType到“中心”
你应该使用dp而不是像素。不,那只会使正方形变大。我的模拟器的屏幕分辨率比基线高。试过了,没有任何区别。编辑了这个问题。