Having done a lot of research on different types of XML drawings, it seems that your LayerDrawable
(layer-list) will scale ShapeDrawables
independently. Then , ImageView
scales the LayerDrawable
. According to this guide from Google , scaling for both ShapeDrawable
and LayerDrawable
is troubling. LayerDrawable
will check the necessary scaling for each element that you have. They have several solutions:
- Set
gravity
to something that does not scale, for example, "center". - determine how to draw as a bitmap.
- Set ImageView to scaleType, which does not scale.
There are two serious problems with this, however ... You can use gravity
for bitmap
only. And you cannot use ShapeDrawable for bitmap
in XML. I tried everything . I would have thought that everything was right. Here is just the thing that fixed it for me.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/imageView1" android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/oval1" android:scaleType="center" /> <ImageView android:id="@+id/imageView2" android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/oval2" android:scaleType="center" /> </FrameLayout>
So: I removed LayerDrawable, split Shapes into my own XML, made two ImageViews. (for ease, I stuck them in FrameLayout). This was the only way to stop scaling.
Testing procedure
Tested in Android 2.1, 3.0, 4.0
scaleType
Image- Changed image
width
and height
- Divided ShapeDrawables
- LayerList changed only
item
with drawable
attribute associated with shared shape
s - Changed LayerList to
bitmap
referring to split shape
s. - Reordered
shape
s
Alternatively, you can do this in code.
source share