A drawable defined in XML that changes the size of another drawable based on its current level.
res/drawable/filename.xml
The filename is used as the resource ID.
ScaleDrawable
.
R.drawable.filename
In XML:
@[package:]drawable/filename
<?xml version="1.0" encoding="utf-8"?> <scale xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/drawable_resource" android:scaleGravity=["top" | "bottom" | "left" | "right" | "center_vertical" | "fill_vertical" | "center_horizontal" | "fill_horizontal" | "center" | "fill" | "clip_vertical" | "clip_horizontal"] android:scaleHeight="percentage" android:scaleWidth="percentage" />
<scale>
attributes:
xmlns:android
"http://schemas.android.com/apk/res/android"
.
android:drawable
android:scaleGravity
Must be one or more (separated by '|') of the following constant values:
top |
Put the object at the top of its container, not changing its size. |
bottom |
Put the object at the bottom of its container, not changing its size. |
left |
Put the object at the left edge of its container, not changing its size. This is the default. |
right |
Put the object at the right edge of its container, not changing its size. |
center_vertical |
Place object in the vertical center of its container, not changing its size. |
fill_vertical |
Grow the vertical size of the object if needed so it completely fills its container. |
center_horizontal |
Place object in the horizontal center of its container, not changing its size. |
fill_horizontal |
Grow the horizontal size of the object if needed so it completely fills its container. |
center |
Place the object in the center of its container in both the vertical and horizontal axis, not changing its size. |
fill |
Grow the horizontal and vertical size of the object if needed so it completely fills its container. |
clip_vertical |
Additional option that can be set to have the top and/or bottom edges of the child clipped to its container's bounds. The clip is based on the vertical gravity: a top gravity clips the bottom edge, a bottom gravity clips the top edge, and neither clips both edges. |
clip_horizontal |
Additional option that can be set to have the left and/or right edges of the child clipped to its container's bounds. The clip is based on the horizontal gravity: a left gravity clips the right edge, a right gravity clips the left edge, and neither clips both edges. |
android:scaleHeight
android:scaleWidth
<?xml version="1.0" encoding="utf-8"?> <scale xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/logo" android:scaleGravity="center_vertical|center_horizontal" android:scaleHeight="80%" android:scaleWidth="80%" />