我尝试使用XML图层列表绘制来创建一个简单的插图。
我有两个形状,一个圆和一个矩形。
我希望圆形不会缩放。
以下是布局:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/shape5"
android:layout_gravity="center"
android:scaleType="center"
/>
</LinearLayout>
这是shape5.xml的可绘制对象
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:top="0dp" android:left="0dp">
<shape android:shape="rectangle" android:scaleType="center">
<stroke android:width="2dp" android:color="@android:color/holo_red_light" />
<size android:width="200dp" android:height="100dp"/>
</shape>
</item>
<item android:top="10dp" android:left="10dp">
<shape android:shape="oval" android:gravity="center" android:scaleType="center" >
<stroke android:width="2dp" android:color="@android:color/holo_blue_light" />
<corners android:radius="10dp" />
<size android:width="20dp" android:height="20dp"/>
</shape>
</item>
</layer-list>
生成的图形如下:
更新:
根据这个答案,我知道通过操作item的android:top、android:left等属性,我可以创建一个虚拟插入线,将我的“形状”按照我想要的比例进行缩放。我检查了一下,是正确的。所以这是一个变通方法。然而,我对它有多么不直观感到非常失望。我仍然希望有人能指点我一个简单的方法来禁用缩放。
更新: 根据Google Android文档页面上的说明,设置ImageView scaleType应该可以防止缩放。但是,在我的情况下,它似乎没有起作用。还有什么遗漏的吗?