Issue
From this developer guide about Layer-list drawables,
All drawable items are scaled to fit the size of the containing View, by default. Thus, placing your images in a layer list at different positions might increase the size of the View and some images scale as appropriate.
In the first sentence, they say that the items are scaled to fit the container view (and Not that the view is scaled according to the size of the items contained in it). Then they say that the size of the container view might increase (which means that the View is being scaled, right?). So doesn't the second sentence contradict the first one? Can somebody explain what is meant there?
android:drawable
Drawable resource. Required. Reference to a drawable resource.
...
To avoid scaling items in the list, use a element inside the element to specify the drawable...
...
For example, the following defines an item that scales to fit its container View:
<item android:drawable="@drawable/image" />
To avoid scaling, the following example uses a element with centered gravity:
<item> <bitmap android:src="@drawable/image" android:gravity="center" /> </item>
Again, they say that
android:drawable
is a required attribute, and then they give an example which does not use this attribute. What is correct?To avoid scaling items in the list, use a
<bitmap>
element inside the<item>
element to specify the drawable and define the gravity to something that does not scale, such as "center"How is
gravity
scalable and how iscenter
as its value make it unscalable?
Solution
It seems that layer-list items are effectively stretched in both X & Y dimensions to fit the container.
You need a drawable for each item. The bitmap child element effectively becomes the drawable for that item.
If you have an empty item (with no drawable resource), it will cause an error when you try to load the layer-list.
Gravity has several options (like
FILL
, which is probably the item's default gravity, orFILL_HORIZONTAL
that stretch the item to fill its container).Additionally, you can set
android:gravity="center"
on an item tag itself (without a<bitmap>
child) and it seems to have the same effect (in API 23, at least).
Answered By - Christopher Boyd
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.