summaryrefslogtreecommitdiffstats
path: root/docs/html/guide/topics/resources/drawable-resource.jd
blob: cee8fc3fcc42de1a9f1edb9fe8542eefd1fc6900 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
page.title=Drawable Resources
parent.title=Resource Types
parent.link=available-resources.html
@jd:body

<div id="qv-wrapper">
  <div id="qv">
    <h2>See also</h2>
    <ol>
      <li><a href="{@docRoot}guide/topics/graphics/2d-graphics.html">2D Graphics</a></li>
    </ol>
  </div>
</div>

<p>A drawable resource is a general concept for a graphic that can be drawn to the screen and which
you can retrieve with APIs such as {@link android.content.res.Resources#getDrawable(int)} or apply
to another XML resource with attributes such as {@code android:drawable} and {@code android:icon}.
There are several different types of drawables:</p>
<dl>
  <dt><a href="#Bitmap">Bitmap File</a><dt>
    <dd>A bitmap graphic file ({@code .png}, {@code .jpg}, or {@code .gif}).
      Creates a {@link android.graphics.drawable.BitmapDrawable}.</dd>
  <dt><a href="#NinePatch">Nine-Patch File</a></dt>
    <dd>A PNG file with stretchable regions to allow image resizing based on content ({@code
.9.png}). Creates a {@link android.graphics.drawable.NinePatchDrawable}.</dd>
  <dt><a href="#LayerList">Layer List</a></dt>
    <dd>A Drawable that manages an array of other Drawables. These are drawn in array order, so the
element with the largest index is be drawn on top. Creates a {@link
android.graphics.drawable.LayerDrawable}.</dd>
  <dt><a href="#StateList">State List</a></dt>
    <dd>An XML file that references different bitmap graphics
    for different states (for example, to use a different image when a button is pressed).
    Creates a {@link android.graphics.drawable.StateListDrawable}.</dd>
  <dt><a href="#LevelList">Level List</a></dt>
    <dd>An XML file that defines a drawable that manages a number of alternate Drawables, each
assigned a maximum numerical value. Creates a {@link
android.graphics.drawable.LevelListDrawable}.</dd>
  <dt><a href="#Transition">Transition Drawable</a></dt>
    <dd>An XML file that defines a drawable that can cross-fade between two drawable resources.
Creates a {@link android.graphics.drawable.TransitionDrawable}.</dd>
  <dt><a href="#Inset">Inset Drawable</a></dt>
    <dd>An XML file that defines a drawable that insets another drawable by a specified distance.
This is useful when a View needs a background drawble that is smaller than the View's actual
bounds.</dd>
  <dt><a href="#Clip">Clip Drawable</a></dt>
    <dd>An XML file that defines a drawable that clips another Drawable based on this Drawable's
current level value. Creates a {@link android.graphics.drawable.ClipDrawable}.</dd>
  <dt><a href="#Scale">Scale Drawable</a></dt>
    <dd>An XML file that defines a drawable that changes the size of another Drawable based on its
current level value.  Creates a {@link android.graphics.drawable.ScaleDrawable}</dd>
  <dt><a href="#Shape">Shape Drawable</a></dt>
    <dd>An XML file that defines a geometric shape, including colors and gradients.
    Creates a {@link android.graphics.drawable.ShapeDrawable}.</dd>
</dl>

<p>Also see the <a href="animation-resource.html">Animation Resource</a> document for how to
create an {@link android.graphics.drawable.AnimationDrawable}.</p>

<p class="note"><strong>Note:</strong> A <a
href="{@docRoot}guide/topics/resources/more-resources.html#Color">color resource</a> can also be
used as a drawable in XML. For example, when creating a <a href="#StateList">state list
drawable</a>, you can reference a color resource for the {@code android:drawable} attribute ({@code
android:drawable="@color/green"}).</p>




<h2 id="Bitmap">Bitmap</h2>

<p>A bitmap image. Android supports bitmap files in a three formats:
{@code .png} (preferred), {@code .jpg} (acceptable), {@code .gif} (discouraged).</p>

<p>You can reference a bitmap file directly, using the filename as the resource ID, or create an
alias resource ID in XML.</p>

<p class="note"><strong>Note:</strong> Bitmap files may be automatically optimized with lossless
image compression by the <code>aapt</code> tool during the build process. For
example, a true-color PNG that does not require more than 256 colors may be converted to an 8-bit
PNG with a color palette. This will result in an image of equal quality but which requires less
memory. So be aware that the image binaries placed in this directory can change during the build. If
you plan on reading an image as a bit stream in order to convert it to a bitmap, put your images in
the <code>res/raw/</code> folder instead, where they will not be optimized.</p>


<h3 id="BitmapFile">Bitmap File</h3>

<p>A bitmap file is a {@code .png}, {@code .jpg}, or {@code .gif} file. Android creates a {@link
android.graphics.drawable.Drawable}
resource for any of these files when you save them in the {@code res/drawable/} directory.</p>

<dl class="xml">

<dt>file location:</dt>
<dd><code>res/drawable/<em>filename</em>.png</code> ({@code .png}, {@code .jpg}, or {@code .gif})<br/>
The filename is used as the resource ID.</dd>

<dt>compiled resource datatype:</dt>
<dd>Resource pointer to a {@link android.graphics.drawable.BitmapDrawable}.</dd>

<dt>resource reference:</dt>
<dd>
In Java: <code>R.drawable.<em>filename</em></code></li><br/>
In XML: <code>@[<em>package</em>:]drawable/<em>filename</em></code>
</dd>

<dt>example:</dt>

<dd>With an image saved at <code>res/drawable/myimage.png</code>, this layout XML applies
the image to a View:
<pre>
&lt;ImageView
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:src="@drawable/myimage" />
</pre>
<p>The following application code retrieves the image as a {@link
android.graphics.drawable.Drawable}:</p>
<pre>
Resources res = {@link android.content.Context#getResources()};
Drawable drawable = res.{@link android.content.res.Resources#getDrawable(int) getDrawable}(R.drawable.myimage);
</pre>
</dd>

<dt>see also:</dt>
<dd>
<ul>
  <li><a href="{@docRoot}guide/topics/graphics/2d-graphics.html">2D Graphics</a></li>
  <li>{@link android.graphics.drawable.BitmapDrawable}</li>
</ul>
</dd>

</dl>




<h3 id="XmlBitmap">XML Bitmap</h3>

<p>An XML bitmap is a resource defined in XML that points to a bitmap file. The effect is an alias for a
raw bitmap file. The XML can specify additional properties for the bitmap such as dithering and tiling.</p>

<p class="note"><strong>Note:</strong> You can use a {@code &lt;bitmap&gt;} element as a child of
an {@code &lt;item&gt;} element. For
example, when creating a <a href="#StateList">state list</a> or <a href="#LayerList">layer list</a>,
you can exclude the {@code android:drawable}
attribute from an {@code &lt;item&gt;} element and nest a {@code &lt;bitmap&gt;} inside it
that defines the drawable item.</p>

<dl class="xml">

<dt>file location:</dt>
<dd><code>res/drawable/<em>filename</em>.xml</code><br/>
The filename is used as the resource ID.</dd>

<dt>compiled resource datatype:</dt>
<dd>Resource pointer to a {@link android.graphics.drawable.BitmapDrawable}.</dd>

<dt>resource reference:</dt>
<dd>
In Java: <code>R.drawable.<em>filename</em></code></li><br/>
In XML: <code>@[<em>package</em>:]drawable/<em>filename</em></code>
</dd>

<dt>syntax:</dt>
<dd>
<pre class="stx">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;<a href="#bitmap-element">bitmap</a>
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@[package:]drawable/<em>drawable_resource</em>"
    android:antialias=["true" | "false"]
    android:dither=["true" | "false"]
    android:filter=["true" | "false"]
    android:gravity=["top" | "bottom" | "left" | "right" | "center_vertical" |
                      "fill_vertical" | "center_horizontal" | "fill_horizontal" |
                      "center" | "fill" | "clip_vertical" | "clip_horizontal"]
    android:tileMode=["disabled" | "clamp" | "repeat" | "mirror"] /&gt;
</pre>
</dd>


<dt>elements:</dt>
<dd>
<dl class="tag-list">

  <dt id="bitmap-element"><code>&lt;bitmap&gt;</code></dt>
    <dd>Defines the bitmap source and its properties.
      <p class="caps">attributes:</p>
      <dl class="atn-list">
        <dt><code>xmlns:android</code></dt>
          <dd><em>String</em>. Defines the XML namespace, which must be
          <code>"http://schemas.android.com/apk/res/android"</code>. This is required only if the
<code>&lt;bitmap&gt;</code> is the root element&mdash;it is not needed when the
<code>&lt;bitmap&gt;</code> is nested inside an <code>&lt;item&gt;</code>.</dd>
        <dt><code>android:src</code></dt>
          <dd><em>Drawable resource</em>. <strong>Required</strong>. Reference to a drawable
resource.</dd>
        <dt><code>android:antialias</code></dt>
          <dd><em>Boolean</em>. Enables or disables antialiasing.</dd>
        <dt><code>android:dither</code></dt>
          <dd><em>Boolean</em>. Enables or disables dithering of the bitmap if the bitmap does not
have the same pixel configuration as the screen (for instance: a ARGB 8888 bitmap with an RGB 565
screen).</dd>
        <dt><code>android:filter</code></dt>
          <dd><em>Boolean</em>. Enables or disables bitmap filtering. Filtering is used when the
bitmap is shrunk or stretched to smooth its apperance.</dd>
        <dt><code>android:gravity</code></dt>
          <dd><em>Keyword</em>. Defines the gravity for the bitmap. The gravity indicates where to
position the drawable in its container if the bitmap is smaller than the container.
            <p>Must be one or more (separated by '|') of the following constant values:</p>
<table>
<tr><th>Value</th><th>Description</th></tr>
<tr><td><code>top</code></td>
<td>Put the object at the top of its container, not changing its size.</td></tr>
<tr><td><code>bottom</code></td>
<td>Put the object at the bottom of its container, not changing its size. </td></tr>
<tr><td><code>left</code></td>
<td>Put the object at the left edge of its container, not changing its size. </td></tr>
<tr><td><code>right</code></td>
<td>Put the object at the right edge of its container, not changing its size. </td></tr>
<tr><td><code>center_vertical</code></td>
<td>Place object in the vertical center of its container, not changing its size. </td></tr>
<tr><td><code>fill_vertical</code></td>
<td>Grow the vertical size of the object if needed so it completely fills its container. </td></tr>
<tr><td><code>center_horizontal</code></td>
<td>Place object in the horizontal center of its container, not changing its size. </td></tr>
<tr><td><code>fill_horizontal</code></td>
<td>Grow the horizontal size of the object if needed so it completely fills its container.
</td></tr>
<tr><td><code>center</code></td>
<td>Place the object in the center of its container in both the vertical and horizontal axis, not
changing its size. </td></tr>
<tr><td><code>fill</code></td>
<td>Grow the horizontal and vertical size of the object if needed so it completely fills its
container. This is the default.</td></tr>
<tr><td><code>clip_vertical</code></td>
<td>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.
</td></tr>
<tr><td><code>clip_horizontal</code></td>
<td>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.
</td></tr>
</table>
          </dd>
        <dt><code>android:tileMode</code></dt>
          <dd><em>Keyword</em>. Defines the tile mode. When the tile mode is enabled, the bitmap is
repeated. Gravity is ignored when the tile mode is enabled.
            <p>Must be one of the following constant values:</p>
<table>
<tr><th>Value</th><th>Description</th></tr>
<tr><td><code>disabled</code></td>
<td>Do not tile the bitmap. This is the default value.</td></tr>
<tr><td><code>clamp</code></td>
<td>Replicates the edge color if the shader draws outside of its original bounds</td></tr>
<tr><td><code>repeat</code></td>
<td>Repeats the shader's image horizontally and vertically.</td></tr>
<tr><td><code>mirror</code></td>
<td>Repeats the shader's image horizontally and vertically, alternating mirror images so that
adjacent images always seam.</td></tr>
</table>

          </dd>
      </dl>
    </dd>

</dl>
</dd> <!-- end  elements and attributes -->

<dt>example:</dt>
<dd>
<pre>
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/icon"
    android:tileMode="repeat" /&gt;
</pre>

</dd>

<dt>see also:</dt>
<dd>
<ul>
  <li>{@link android.graphics.drawable.BitmapDrawable}</li>
  <li><a href="{@docRoot}guide/topics/resources/providing-resources.html#AliasResources">Creating
alias resources</a>
</ul>
</dd>

</dl>






<h2 id="NinePatch">Nine-Patch</h2>

<p>A {@link android.graphics.NinePatch} is a PNG image in which you can define stretchable regions
that Android scales when content within the View exceeds the normal image bounds. You
typically assign this type of image as the background of a View that has at least one dimension set
to {@code "wrap_content"}, and when the View grows to accomodate the content, the Nine-Patch image
is also scaled to match the size of the View. An example use of a Nine-Patch image is the
background used by Android's standard {@link android.widget.Button} widget, which must stretch to
accommodate the text (or image) inside the button.</p>

<p>Same as with a normal <a href="#Bitmap">bitmap</a>, you can reference a Nine-Patch file directly
or from a resource defined by XML.</p>

<p>For a complete discussion about how to create a Nine-Patch file with stretchable regions,
see the <a href="{@docRoot}guide/topics/graphics/2d-graphics.html#nine-patch">2D Graphics</a>
document.</p>


<h3 id="NinePatchFile">Nine-Patch File</h3>

<dl class="xml">

<dt>file location:</dt>
<dd><code>res/drawable/<em>filename</em>.9.png</code><br/>
The filename is used as the resource ID.</dd>

<dt>compiled resource datatype:</dt>
<dd>Resource pointer to a {@link android.graphics.drawable.NinePatchDrawable}.</dd>

<dt>resource reference:</dt>

<dd>
In Java: <code>R.drawable.<em>filename</em></code><br/>
In XML: <code>@[<em>package</em>:]drawable/<em>filename</em></code>
</dd>

<dt>example:</dt>

<dd>With an image saved at <code>res/drawable/myninepatch.9.png</code>, this layout XML
applies the Nine-Patch to a View:
<pre>
&lt;Button
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:background="@drawable/myninepatch" />
</pre>
</dd>

<dt>see also:</dt>

<dd>
<ul>
  <li><a href="{@docRoot}guide/topics/graphics/2d-graphics.html#nine-patch">2D Graphics</a></li>
  <li>{@link android.graphics.drawable.NinePatchDrawable}</li>
</ul>
</dd>

</dl>




<h3 id="NinePatchXml">XML Nine-Patch</h3>

<p>An XML Nine-Patch is a resource defined in XML that points to a Nine-Patch file. The XML can
specify dithering for the image.</p>

<dl class="xml">

<dt>file location:</dt>
<dd><code>res/drawable/<em>filename</em>.xml</code><br/>
The filename is used as the resource ID.</dd>

<dt>compiled resource datatype:</dt>
<dd>Resource pointer to a {@link android.graphics.drawable.NinePatchDrawable}.</dd>

<dt>resource reference:</dt>

<dd>
In Java: <code>R.drawable.<em>filename</em></code><br/>
In XML: <code>@[<em>package</em>:]drawable/<em>filename</em></code>
</dd>


<dt>syntax:</dt>

<dd>
<pre class="stx">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;<a href="#ninepatch-element">nine-patch</a>
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@[package:]drawable/<em>drawable_resource</em>"
    android:dither=["true" | "false"] /&gt;
</pre>
</dd>


<dt>elements:</dt>

<dd>
<dl class="tag-list">

  <dt id="ninepatch-element"><code>&lt;nine-patch&gt;</code></dt>
    <dd>Defines the Nine-Patch source and its properties.
      <p class="caps">attributes:</p>
      <dl class="atn-list">
        <dt><code>xmlns:android</code></dt>
          <dd><em>String</em>. <strong>Required.</strong> Defines the XML namespace, which must be
          <code>"http://schemas.android.com/apk/res/android"</code>.
        <dt><code>android:src</code></dt>
          <dd><em>Drawable resource</em>. <strong>Required</strong>. Reference to a Nine-Patch
file.</dd>
        <dt><code>android:dither</code></dt>
          <dd><em>Boolean</em>. Enables or disables dithering of the bitmap if the bitmap does not
have the same pixel configuration as the screen (for instance: a ARGB 8888 bitmap with an RGB 565
screen).</dd>
      </dl>
    </dd>
</dl>
</dd>


<dt>example:</dt>

<dd>
<pre class="stx">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;nine-patch xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/myninepatch"
    android:dither="false" /&gt;
</pre>
</dd>
</dl>






<h2 id="LayerList">Layer List</h2>

<p>A {@link android.graphics.drawable.LayerDrawable} is a drawable object
that manages an array of other drawables. Each drawable in the list is drawn in the order of the
list&mdash;the last drawable in the list is drawn on top.</p>

<p>Each drawable is represented by an {@code &lt;item&gt;} element inside a single {@code
&lt;layer-list&gt;} element.</p>

<dl class="xml">

<dt>file location:</dt>
<dd><code>res/drawable/<em>filename</em>.xml</code><br/>
The filename is used as the resource ID.</dd>

<dt>compiled resource datatype:</dt>
<dd>Resource pointer to a {@link android.graphics.drawable.LayerDrawable}.</dd>

<dt>resource reference:</dt>

<dd>
In Java: <code>R.drawable.<em>filename</em></code><br/>
In XML: <code>@[<em>package</em>:]drawable/<em>filename</em></code>
</dd>

<dt>syntax:</dt>

<dd>
<pre class="stx">
&lt;?xml version="1.0" encoding="utf-8"?>
&lt;<a href="#layerlist-element">layer-list</a>
    xmlns:android="http://schemas.android.com/apk/res/android" &gt;
    &lt;<a href="#layerlist-item-element">item</a>
        android:drawable="@[package:]drawable/<em>drawable_resource</em>"
        android:id="@[+][<em>package</em>:]id/<i>resource_name</i>"
        android:top="<em>dimension</em>"
        android:right="<em>dimension</em>"
        android:bottom="<em>dimension</em>"
        android:left="<em>dimension</em>" /&gt;
&lt;/layer-list>
</pre>
</dd>

<dt>elements:</dt>

<dd>
<dl class="tag-list">

  <dt id="layerlist-element"><code>&lt;layer-list&gt;</code></dt>
    <dd><strong>Required.</strong> This must be the root element. Contains one or more {@code
&lt;item>} elements.
      <p class="caps">attributes:</p>
      <dl class="atn-list">
        <dt><code>xmlns:android</code></dt>
          <dd><em>String</em>. <strong>Required.</strong> Defines the XML namespace, which must be
          <code>"http://schemas.android.com/apk/res/android"</code>.
      </dl>
    </dd>
  <dt id="layerlist-item-element"><code>&lt;item&gt;</code></dt>
    <dd>Defines a drawable to place in the layer drawable, in a position defined by its attributes.
Must be a child of a <code>&lt;selector&gt;</code> element. Accepts child {@code &lt;bitmap&gt;}
elements.
      <p class="caps">attributes:</p>
      <dl class="atn-list">
        <dt><code>android:drawable</code></dt>
          <dd><em>Drawable resource</em>. <strong>Required</strong>. Reference to a drawable
resource.</dd>
        <dt><code>android:id</code></dt>
          <dd><em>Resource ID</em>. A unique resource ID for this drawable. To create a new resource
ID for this item, use the form:
<code>"@+id/<em>name</em>"</code>. The plus symbol indicates that this should be created as a new
ID. You can use this identifier to
retrieve and modify the drawable with {@link android.view.View#findViewById(int)
View.findViewById()} or {@link android.app.Activity#findViewById(int) Activity.findViewById()}.</dd>
        <dt><code>android:top</code></dt>
          <dd><em>Integer</em>. The top offset in pixels.</dd>
        <dt><code>android:right</code></dt>
          <dd><em>Integer</em>. The right offset in pixels.</dd>
        <dt><code>android:bottom</code></dt>
          <dd><em>Integer</em>. The bottom offset in pixels.</dd>
        <dt><code>android:left</code></dt>
          <dd><em>Integer</em>. The left offset in pixels.</dd>
      </dl>
      <p>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. To avoid
scaling items in the list, use a {@code &lt;bitmap&gt;} element inside the {@code
&lt;item&gt;} element to specify the drawable and define the gravity to something that does not
scale, such as {@code "center"}. For example, the following {@code &lt;item&gt;} defines an item
that scales to fit its container View:</p>
<pre>
&lt;item android:drawable="@drawable/image" /&gt;
</pre>

<p>To avoid scaling, the following example uses a {@code &lt;bitmap&gt;} element with centered
gravity:</p>
<pre>
&lt;item&gt;
  &lt;bitmap android:src="<b>@drawable/image</b>"
          android:gravity="center" /&gt;
&lt;/item&gt;
</pre>
    </dd>

</dl>
</dd> <!-- end  elements and attributes -->

<dt>example:</dt>

<dd>XML file saved at <code>res/drawable/layers.xml</code>:
<pre>
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android"&gt;
    &lt;item&gt;
      &lt;bitmap android:src="@drawable/android_red"
        android:gravity="center" /&gt;
    &lt;/item&gt;
    &lt;item android:top="10dp" android:left="10dp"&gt;
      &lt;bitmap android:src="@drawable/android_green"
        android:gravity="center" /&gt;
    &lt;/item&gt;
    &lt;item android:top="20dp" android:left="20dp"&gt;
      &lt;bitmap android:src="@drawable/android_blue"
        android:gravity="center" /&gt;
    &lt;/item&gt;
&lt;/layer-list&gt;
</pre>
<p>Notice that this example uses a nested {@code &lt;bitmap&gt;} element to define the drawable
resource for each item with a "center" gravity. This ensures that none of the images are scaled to
fit the size of the container, due to resizing caused by the offset images.</p>

<p>This layout XML applies the drawable to a View:</p>
<pre>
&lt;ImageView
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:src="@drawable/layers" /&gt;
</pre>

<p>The result is a stack of increasingly offset images:</p>
<img src="{@docRoot}images/resources/layers.png" alt="" />
</dd> <!-- end example -->

<dt>see also:</dt>
<dd>
<ul>
  <li>{@link android.graphics.drawable.LayerDrawable}</li>
</ul>
</dd>

</dl>








<h2 id="StateList">State List</h2>

<p>A {@link android.graphics.drawable.StateListDrawable} is a drawable object defined in XML
that uses a several different images to represent the same graphic, depending on the state of
the object. For example, a {@link
android.widget.Button} widget can exist in one of several different states (pressed, focused,
or niether) and, using a state list drawable, you can provide a different background image for each
state.</p>

<p>You can describe the state list in an XML file. Each graphic is represented by an {@code
&lt;item>} element inside a single {@code &lt;selector>} element. Each {@code &lt;item>}
uses various attributes to describe the state in which it should be used as the graphic for the
drawable.</p>

<p>During each state change, the state list is traversed top to bottom and the first item that
matches the current state is used&mdash;the selection is <em>not</em> based on the "best
match," but simply the first item that meets the minimum criteria of the state.</p>

<dl class="xml">

<dt>file location:</dt>
<dd><code>res/drawable/<em>filename</em>.xml</code><br/>
The filename is used as the resource ID.</dd>

<dt>compiled resource datatype:</dt>
<dd>Resource pointer to a {@link android.graphics.drawable.StateListDrawable}.</dd>

<dt>resource reference:</dt>

<dd>
In Java: <code>R.drawable.<em>filename</em></code><br/>
In XML: <code>@[<em>package</em>:]drawable/<em>filename</em></code>
</dd>

<dt>syntax:</dt>

<dd>
<pre class="stx">
&lt;?xml version="1.0" encoding="utf-8"?>
&lt;<a href="#selector-element">selector</a> xmlns:android="http://schemas.android.com/apk/res/android"
    android:constantSize=["true" | "false"]
    android:dither=["true" | "false"]
    android:variablePadding=["true" | "false"] >
    &lt;<a href="#item-element">item</a>
        android:drawable="@[package:]drawable/<em>drawable_resource</em>"
        android:state_pressed=["true" | "false"]
        android:state_focused=["true" | "false"]
        android:state_selected=["true" | "false"]
        android:state_checkable=["true" | "false"]
        android:state_checked=["true" | "false"]
        android:state_enabled=["true" | "false"]
        android:state_window_focused=["true" | "false"] />
&lt;/selector>
</pre>
</dd>

<dt>elements:</dt>

<dd>
<dl class="tag-list">

  <dt id="selector-element"><code>&lt;selector&gt;</code></dt>
    <dd><strong>Required.</strong> This must be the root element. Contains one or more {@code
&lt;item>} elements.
      <p class="caps">attributes:</p>
      <dl class="atn-list">
        <dt><code>xmlns:android</code></dt>
          <dd><em>String</em>. <strong>Required.</strong> Defines the XML namespace, which must be
          <code>"http://schemas.android.com/apk/res/android"</code>.
        <dt><code>android:constantSize</code></dt>
          <dd><em>Boolean</em>. "true" if the drawable's reported internal size remains constant as the state
changes (the size is the maximum of all of the states); "false" if the size varies based on
the current state. Default is false.</dd>
        <dt><code>android:dither</code></dt>
          <dd><em>Boolean</em>. "true" to enable dithering of the bitmap if the bitmap does not have the same pixel
configuration as the screen (for instance, an ARGB 8888 bitmap with an RGB 565 screen); "false" to
disable dithering. Default is true.</dd>
        <dt><code>android:variablePadding</code></dt>
          <dd><em>Boolean</em>. "true" if the drawable's padding should change based on the current
state that is selected; "false" if the padding should stay the same (based on the maximum
padding of all the states). Enabling this feature requires that you deal with
performing layout when the state changes, which is often not supported. Default is false.</dd>
      </dl>
    </dd>
  <dt id="item-element"><code>&lt;item&gt;</code></dt>
    <dd>Defines a drawable to use during certain states, as described by its attributes. Must be a
child of a <code>&lt;selector&gt;</code> element.
      <p class="caps">attributes:</p>
      <dl class="atn-list">
        <dt><code>android:drawable</code></dt>
          <dd><em>Drawable resource</em>. <strong>Required</strong>. Reference to a drawable resource.</dd>
        <dt><code>android:state_pressed</code></dt>
          <dd><em>Boolean</em>. "true" if this item should be used when the object is pressed (such as when a button
is touched/clicked); "false" if this item should be used in the default, non-pressed state.</dd>
        <dt><code>android:state_focused</code></dt>
          <dd><em>Boolean</em>. "true" if this item should be used when the object is focused (such as when a button
is highlighted using the trackball/d-pad); "false" if this item should be used in the default,
non-focused state.</dd>
        <dt><code>android:state_selected</code></dt>
          <dd><em>Boolean</em>. "true" if this item should be used when the object is selected (such as when a
tab is opened); "false" if this item should be used when the object is not selected.</dd>
        <dt><code>android:state_checkable</code></dt>
          <dd><em>Boolean</em>. "true" if this item should be used when the object is checkable; "false" if this
item should be used when the object is not checkable. (Only useful if the object can
transition between a checkable and non-checkable widget.)</dd>
        <dt><code>android:state_checked</code></dt>
          <dd><em>Boolean</em>. "true" if this item should be used when the object is checked; "false" if it
should be used when the object is un-checked.</dd>
        <dt><code>android:state_enabled</code></dt>
          <dd><em>Boolean</em>. "true" if this item should be used when the object is enabled (capable of
receiving touch/click events); "false" if it should be used when the object is disabled.</dd>
        <dt><code>android:state_window_focused</code></dt>
          <dd><em>Boolean</em>. "true" if this item should be used when the application window has focus (the
application is in the foreground), "false" if this item should be used when the application
window does not have focus (for example, if the notification shade is pulled down or a dialog appears).</dd>
      </dl>
      <p class="note"><strong>Note:</strong> Remember that Android applies the first item in the state list that
matches the current state of the object. So, if the first item in the list contains
none of the state attributes above, then it is applied every time, which is why your
default value should always be last (as demonstrated in the following example).</p>
    </dd>

</dl>
</dd> <!-- end  elements and attributes -->

<dt>example:</dt>

<dd>XML file saved at <code>res/drawable/button.xml</code>:
<pre>
&lt;?xml version="1.0" encoding="utf-8"?>
&lt;selector xmlns:android="http://schemas.android.com/apk/res/android">
    &lt;item android:state_pressed="true"
          android:drawable="@drawable/button_pressed" /> &lt;!-- pressed --&gt;
    &lt;item android:state_focused="true"
          android:drawable="@drawable/button_focused" /> &lt;!-- focused --&gt;
    &lt;item android:drawable="@drawable/button_normal" /> &lt;!-- default --&gt;
&lt;/selector>
</pre>

<p>This layout XML applies the state list drawable to a Button:</p>
<pre>
&lt;Button
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:background="@drawable/button" />
</pre>
</dd> <!-- end example -->

<dt>see also:</dt>
<dd>
<ul>
  <li>{@link android.graphics.drawable.StateListDrawable}</li>
</ul>
</dd>

</dl>








<h2 id="LevelList">Level List</h2>

<p>A Drawable that manages a number of alternate Drawables, each assigned a maximum numerical
value. Setting the level value of the drawable with {@link
android.graphics.drawable.Drawable#setLevel(int) setLevel()} loads the drawable resource in the
level list that has a {@code android:maxLevel} value greater than or equal to the value
passed to the method.</p>

<dl class="xml">

<dt>file location:</dt>
<dd><code>res/drawable/<em>filename</em>.xml</code><br/>
The filename is used as the resource ID.</dd>

<dt>compiled resource datatype:</dt>
<dd>Resource pointer to a {@link android.graphics.drawable.LevelListDrawable}.</dd>

<dt>resource reference:</dt>

<dd>
In Java: <code>R.drawable.<em>filename</em></code><br/>
In XML: <code>@[<em>package</em>:]drawable/<em>filename</em></code>
</dd>

<dt>syntax:</dt>

<dd>
<pre class="stx">
&lt;?xml version="1.0" encoding="utf-8"?>
&lt;<a href="#levellist-element">level-list</a>
    xmlns:android="http://schemas.android.com/apk/res/android" &gt;
    &lt;<a href="#levellist-item-element">item</a>
        android:drawable="@drawable/<i>drawable_resource</i>"
        android:maxLevel="<i>integer</i>"
        android:minLevel="<i>integer</i>" /&gt;
&lt;/level-list&gt;
</pre>
</dd>

<dt>elements:</dt>

<dd>
<dl class="tag-list">

  <dt id="levellist-element"><code>&lt;level-list&gt;</code></dt>
  <dd>This must be the root element. Contains one or more {@code &lt;item&gt;} elements.
    <p class="caps">attributes:</p>
    <dl class="atn-list">
      <dt><code>xmlns:android</code></dt>
        <dd><em>String</em>. <strong>Required.</strong> Defines the XML namespace, which must be
        <code>"http://schemas.android.com/apk/res/android"</code>.
    </dl>
  </dd>

  <dt id="levellist-item-element"><code>&lt;item&gt;</code></dt>
  <dd>Defines a drawable to use at a certain level.
    <p class="caps">attributes:</p>
    <dl class="atn-list">
      <dt><code>android:drawable</code></dt>
        <dd><em>Drawable resource</em>. <strong>Required</strong>. Reference to a drawable
resource to be inset.</dd>
      <dt><code>android:maxLevel</code></dt>
        <dd><em>Integer</em>. The maximum level allowed for this item.</dd>
      <dt><code>android:minLevel</code></dt>
        <dd><em>Integer</em>. The minimum level allowed for this item.</dd>
    </dl>
  </dd>
</dl>

</dd>

<dt>example:</dt>

<dd>

<pre>
&lt;?xml version="1.0" encoding="utf-8"?>
&lt;level-list xmlns:android="http://schemas.android.com/apk/res/android" &gt;
    &lt;item
        android:drawable="@drawable/status_off"
        android:maxLevel="0" /&gt;
    &lt;item
        android:drawable="@drawable/status_on"
        android:maxLevel="1" /&gt;
&lt;/level-list&gt;
</pre>
<p>Once this is applied to a {@link android.view.View}, the level can be changed with {@link
android.graphics.drawable.Drawable#setLevel(int) setLevel()} or {@link
android.widget.ImageView#setImageLevel(int) setImageLevel()}.</p>

</dd>

<dt>see also:</dt>

<dd>
<ul>
  <li>{@link android.graphics.drawable.LevelListDrawable}</li>
</ul>
</dd>

</dl>






<h2 id="Transition">Transition Drawable</h2>

<p>A {@link android.graphics.drawable.TransitionDrawable} is a drawable object
that can cross-fade between the two drawable resources.</p>

<p>Each drawable is represented by an {@code &lt;item&gt;} element inside a single {@code
&lt;transition&gt;} element. No more than two items are supported. To transition forward, call
{@link android.graphics.drawable.TransitionDrawable#startTransition(int) startTransition()}. To
transition backward, call {@link android.graphics.drawable.TransitionDrawable#reverseTransition(int)
reverseTransition()}.</p>

<dl class="xml">

<dt>file location:</dt>
<dd><code>res/drawable/<em>filename</em>.xml</code><br/>
The filename is used as the resource ID.</dd>

<dt>compiled resource datatype:</dt>
<dd>Resource pointer to a {@link android.graphics.drawable.TransitionDrawable}.</dd>

<dt>resource reference:</dt>

<dd>
In Java: <code>R.drawable.<em>filename</em></code><br/>
In XML: <code>@[<em>package</em>:]drawable/<em>filename</em></code>
</dd>

<dt>syntax:</dt>

<dd>
<pre class="stx">
&lt;?xml version="1.0" encoding="utf-8"?>
&lt;<a href="#transition-element">transition</a>
xmlns:android="http://schemas.android.com/apk/res/android" &gt;
    &lt;<a href="#transition-item-element">item</a>
        android:drawable="@[package:]drawable/<em>drawable_resource</em>"
        android:id="@[+][<em>package</em>:]id/<i>resource_name</i>"
        android:top="<em>dimension</em>"
        android:right="<em>dimension</em>"
        android:bottom="<em>dimension</em>"
        android:left="<em>dimension</em>" /&gt;
&lt;/transition>
</pre>
</dd>

<dt>elements:</dt>

<dd>
<dl class="tag-list">

  <dt id="transition-element"><code>&lt;transition&gt;</code></dt>
    <dd><strong>Required.</strong> This must be the root element. Contains one or more {@code
&lt;item>} elements.
      <p class="caps">attributes:</p>
      <dl class="atn-list">
        <dt><code>xmlns:android</code></dt>
          <dd><em>String</em>. <strong>Required.</strong> Defines the XML namespace, which must be
          <code>"http://schemas.android.com/apk/res/android"</code>.
      </dl>
    </dd>
  <dt id="transition-item-element"><code>&lt;item&gt;</code></dt>
    <dd>Defines a drawable to use as part of the drawable transition.
Must be a child of a <code>&lt;transition&gt;</code> element. Accepts child {@code &lt;bitmap&gt;}
elements.
      <p class="caps">attributes:</p>
      <dl class="atn-list">
        <dt><code>android:drawable</code></dt>
          <dd><em>Drawable resource</em>. <strong>Required</strong>. Reference to a drawable
resource.</dd>
        <dt><code>android:id</code></dt>
          <dd><em>Resource ID</em>. A unique resource ID for this drawable. To create a new resource
ID for this item, use the form:
<code>"@+id/<em>name</em>"</code>. The plus symbol indicates that this should be created as a new
ID. You can use this identifier to
retrieve and modify the drawable with {@link android.view.View#findViewById(int)
View.findViewById()} or {@link android.app.Activity#findViewById(int) Activity.findViewById()}.</dd>
        <dt><code>android:top</code></dt>
          <dd><em>Integer</em>. The top offset in pixels.</dd>
        <dt><code>android:right</code></dt>
          <dd><em>Integer</em>. The right offset in pixels.</dd>
        <dt><code>android:bottom</code></dt>
          <dd><em>Integer</em>. The bottom offset in pixels.</dd>
        <dt><code>android:left</code></dt>
          <dd><em>Integer</em>. The left offset in pixels.</dd>
      </dl>
    </dd>

</dl>
</dd> <!-- end  elements and attributes -->

<dt>example:</dt>

<dd>XML file saved at <code>res/drawable/transition.xml</code>:
<pre>
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;transition xmlns:android="http://schemas.android.com/apk/res/android"&gt;
    &lt;item android:drawable="@drawable/on" /&gt;
    &lt;item android:drawable="@drawable/off" /&gt;
&lt;/transition&gt;
</pre>

<p>This layout XML applies the drawable to a View:</p>
<pre>
&lt;ImageButton
    android:id="@+id/button"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:src="@drawable/transition" /&gt;
</pre>

<p>And the following code performs a 500ms transition from the first item to the second:</p>
<pre>
ImageButton button = (ImageButton) findViewById(R.id.button);
TransitionDrawable drawable = (TransitionDrawable) button.getDrawable();
drawable.startTransition(500);
</pre>

</dd> <!-- end example -->

<dt>see also:</dt>

<dd>
<ul>
  <li>{@link android.graphics.drawable.TransitionDrawable}</li>
</ul>
</dd>

</dl>





<h2 id="Inset">Inset Drawable</h2>

<p>A drawable defined in XML that insets another drawable by a specified distance. This is useful
when a View needs a background that is smaller than the View's actual bounds.</p>

<dl class="xml">

<dt>file location:</dt>
<dd><code>res/drawable/<em>filename</em>.xml</code><br/>
The filename is used as the resource ID.</dd>

<dt>compiled resource datatype:</dt>
<dd>Resource pointer to a {@link android.graphics.drawable.InsetDrawable}.</dd>

<dt>resource reference:</dt>

<dd>
In Java: <code>R.drawable.<em>filename</em></code><br/>
In XML: <code>@[<em>package</em>:]drawable/<em>filename</em></code>
</dd>

<dt>syntax:</dt>

<dd>
<pre class="stx">
&lt;?xml version="1.0" encoding="utf-8"?>
&lt;<a href="#inset-element">inset</a>
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/<i>drawable_resource</i>"
    android:insetTop="<i>dimension</i>"
    android:insetRight="<i>dimension</i>"
    android:insetBottom="<i>dimension</i>"
    android:insetLeft="<i>dimension</i>" /&gt;
</pre>
</dd>

<dt>elements:</dt>

<dd>
<dl class="tag-list">

  <dt id="inset-element"><code>&lt;inset&gt;</code></dt>
  <dd>Defines the inset drawable. This must be the root element.
    <p class="caps">attributes:</p>
    <dl class="atn-list">
      <dt><code>xmlns:android</code></dt>
        <dd><em>String</em>. <strong>Required.</strong> Defines the XML namespace, which must be
        <code>"http://schemas.android.com/apk/res/android"</code>.
      <dt><code>android:drawable</code></dt>
        <dd><em>Drawable resource</em>. <strong>Required</strong>. Reference to a drawable
resource to be inset.</dd>
      <dt><code>android:insetTop</code></dt>
        <dd><em>Dimension</em>. The top inset, as a dimension value or <a
href="more-resources.html#Dimension">dimension resource</a></dd>
      <dt><code>android:insetRight</code></dt>
        <dd><em>Dimension</em>. The right inset, as a dimension value or <a
href="more-resources.html#Dimension">dimension resource</a></dd>
      <dt><code>android:insetBottom</code></dt>
        <dd><em>Dimension</em>. The bottom inset, as a dimension value or <a
href="more-resources.html#Dimension">dimension resource</a></dd>
      <dt><code>android:insetLeft</code></dt>
        <dd><em>Dimension</em>. The left inset, as a dimension value or <a
href="more-resources.html#Dimension">dimension resource</a></dd>
    </dl>
  </dd>
</dl>

</dd>

<dt>example:</dt>

<dd>
<pre>
&lt;?xml version="1.0" encoding="utf-8"?>
&lt;inset xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/background"
    android:insetTop="10dp"
    android:insetLeft="10dp" /&gt;
</pre>
</dd>

<dt>see also:</dt>

<dd>
<ul>
  <li>{@link android.graphics.drawable.InsetDrawable}</li>
</ul>
</dd>

</dl>








<h2 id="Clip">Clip Drawable</h2>

<p>A drawable defined in XML that clips another drawable based on this Drawable's current level. You
can control how much the child drawable gets clipped in width and height based on the level, as well
as a gravity to control where it is placed in its overall container. Most often used to implement
things like progress bars.</p>

<dl class="xml">

<dt>file location:</dt>
<dd><code>res/drawable/<em>filename</em>.xml</code><br/>
The filename is used as the resource ID.</dd>

<dt>compiled resource datatype:</dt>
<dd>Resource pointer to a {@link android.graphics.drawable.ClipDrawable}.</dd>

<dt>resource reference:</dt>

<dd>
In Java: <code>R.drawable.<em>filename</em></code><br/>
In XML: <code>@[<em>package</em>:]drawable/<em>filename</em></code>
</dd>

<dt>syntax:</dt>

<dd>
<pre class="stx">
&lt;?xml version="1.0" encoding="utf-8"?>
&lt;<a href="#clip-element">clip</a>
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/<i>drawable_resource</i>"
    android:clipOrientation=["horizontal" | "vertical"]
    android:gravity=["top" | "bottom" | "left" | "right" | "center_vertical" |
                     "fill_vertical" | "center_horizontal" | "fill_horizontal" |
                     "center" | "fill" | "clip_vertical" | "clip_horizontal"] /&gt;
</pre>
</dd>

<dt>elements:</dt>

<dd>
<dl class="tag-list">

  <dt id="clip-element"><code>&lt;clip&gt;</code></dt>
  <dd>Defines the clip drawable. This must be the root element.
    <p class="caps">attributes:</p>
    <dl class="atn-list">
      <dt><code>xmlns:android</code></dt>
        <dd><em>String</em>. <strong>Required.</strong> Defines the XML namespace, which must be
        <code>"http://schemas.android.com/apk/res/android"</code>.
      <dt><code>android:drawable</code></dt>
        <dd><em>Drawable resource</em>. <strong>Required</strong>. Reference to a drawable
resource to be clipped.</dd>
      <dt><code>android:clipOrientation</code></dt>
        <dd><em>Keyword</em>. The orientation for the clip.
          <p>Must be one of the following constant values:</p>
<table>
<tr><th>Value</th><th>Description</th></tr>
<tr><td><code>horizontal</code></td>
<td>Clip the drawable horizontally.</td></tr>
<tr><td><code>vertical</code></td>
<td>Clip the drawable vertically.</td></tr>
</table>
        </dd>
      <dt><code>android:gravity</code></dt>
        <dd><em>Keyword</em>. Specifies where to clip within the drawable.
          <p>Must be one or more (separated by '|') of the following constant values:</p>
<table>
<tr><th>Value</th><th>Description</th></tr>
<tr><td><code>top</code></td>
<td>Put the object at the top of its container, not changing its size. When {@code
clipOrientation} is {@code "vertical"}, clipping occurs at the bottom of the drawable.</td></tr>
<tr><td><code>bottom</code></td>
<td>Put the object at the bottom of its container, not changing its size. When {@code
clipOrientation} is {@code "vertical"}, clipping occurs at the top of the drawable.</td></tr>
<tr><td><code>left</code></td>
<td>Put the object at the left edge of its container, not changing its size. This is the
default. When {@code clipOrientation} is {@code "horizontal"}, clipping occurs at the right side of
the drawable. This is the default.</td></tr>
<tr><td><code>right</code></td>
<td>Put the object at the right edge of its container, not changing its size. When {@code
clipOrientation} is {@code "horizontal"}, clipping occurs at the left side of
the drawable.</td></tr>
<tr><td><code>center_vertical</code></td>
<td>Place object in the vertical center of its container, not changing its size. Clipping behaves
the same as when gravity is {@code "center"}.</td></tr>
<tr><td><code>fill_vertical</code></td>
<td>Grow the vertical size of the object if needed so it completely fills its container. When {@code
clipOrientation} is {@code "vertical"}, no clipping occurs because the drawable fills the
vertical space (unless the drawable level is 0, in which case it's not visible).</td></tr>
<tr><td><code>center_horizontal</code></td>
<td>Place object in the horizontal center of its container, not changing its size.
Clipping behaves the same as when gravity is {@code "center"}.</td></tr>
<tr><td><code>fill_horizontal</code></td>
<td>Grow the horizontal size of the object if needed so it completely fills its container. When
{@code clipOrientation} is {@code "horizontal"}, no clipping occurs because the drawable fills the
horizontal space (unless the drawable level is 0, in which case it's not visible).
</td></tr>
<tr><td><code>center</code></td>
<td>Place the object in the center of its container in both the vertical and horizontal axis, not
changing its size. When {@code
clipOrientation} is {@code "horizontal"}, clipping occurs on the left and right. When {@code
clipOrientation} is {@code "vertical"}, clipping occurs on the top and bottom.</td></tr>
<tr><td><code>fill</code></td>
<td>Grow the horizontal and vertical size of the object if needed so it completely fills its
container. No clipping occurs because the drawable fills the
horizontal and vertical space (unless the drawable level is 0, in which case it's not
visible).</td></tr>
<tr><td><code>clip_vertical</code></td>
<td>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.
</td></tr>
<tr><td><code>clip_horizontal</code></td>
<td>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.
</td></tr>
</table></dd>
    </dl>
  </dd>
</dl>

</dd> <!-- end  elements and attributes -->

<dt>example:</dt>

<dd>XML file saved at <code>res/drawable/clip.xml</code>:
<pre>
&lt;?xml version="1.0" encoding="utf-8"?>
&lt;clip xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/android"
    android:clipOrientation="horizontal"
    android:gravity="left" /&gt;
&lt;/clip>
</pre>
    <p>The following layout XML applies the clip drawable to a View:</p>
<pre>
&lt;ImageView
    android:id="@+id/image"
    android:background="@drawable/clip"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content" />
</pre>

    <p>The following code gets the drawable and increases the amount of clipping in order to
progressively reveal the image:</p>
<pre>
ImageView imageview = (ImageView) findViewById(R.id.image);
ClipDrawable drawable = (ClipDrawable) imageview.getDrawable();
drawable.setLevel(drawable.getLevel() + 1000);
</pre>

<p>Increasing the level reduces the amount of clipping and slowly reveals the image. Here it is
at a level of 7000:</p>
<img src="{@docRoot}images/resources/clip.png" alt="" />

<p class="note"><strong>Note:</strong> The default level is 0, which is fully clipped so the image
is not visible. When the level is 10,000, the image is not clipped and completely visible.</p>
</dd> <!-- end example -->

<dt>see also:</dt>

<dd>
<ul>
  <li>{@link android.graphics.drawable.ClipDrawable}</li>
</ul>
</dd>

</dl>









<h2 id="Scale">Scale Drawable</h2>

<p>A drawable defined in XML that changes the size of another drawable based on its current
level.</p>

<dl class="xml">

<dt>file location:</dt>
<dd><code>res/drawable/<em>filename</em>.xml</code><br/>
The filename is used as the resource ID.</dd>

<dt>compiled resource datatype:</dt>
<dd>Resource pointer to a {@link android.graphics.drawable.ScaleDrawable}.</dd>

<dt>resource reference:</dt>

<dd>
In Java: <code>R.drawable.<em>filename</em></code><br/>
In XML: <code>@[<em>package</em>:]drawable/<em>filename</em></code>
</dd>

<dt>syntax:</dt>

<dd>
<pre class="stx">
&lt;?xml version="1.0" encoding="utf-8"?>
&lt;<a href="#scale-element">scale</a>
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/<i>drawable_resource</i>"
    android:scaleGravity=["top" | "bottom" | "left" | "right" | "center_vertical" |
                          "fill_vertical" | "center_horizontal" | "fill_horizontal" |
                          "center" | "fill" | "clip_vertical" | "clip_horizontal"]
    android:scaleHeight="<i>percentage</i>"
    android:scaleWidth="<i>percentage</i>" /&gt;
</pre>
</dd>

<dt>elements:</dt>

<dd>
<dl class="tag-list">

  <dt id="scale-element"><code>&lt;scale&gt;</code></dt>
  <dd>Defines the scale drawable. This must be the root element.
    <p class="caps">attributes:</p>
    <dl class="atn-list">
      <dt><code>xmlns:android</code></dt>
        <dd><em>String</em>. <strong>Required.</strong> Defines the XML namespace, which must be
        <code>"http://schemas.android.com/apk/res/android"</code>.
      <dt><code>android:drawable</code></dt>
        <dd><em>Drawable resource</em>. <strong>Required</strong>. Reference to a drawable
resource.</dd>
      <dt><code>android:scaleGravity</code></dt>
        <dd><em>Keyword</em>. Specifies the gravity position after scaling.
          <p>Must be one or more (separated by '|') of the following constant values:</p>
<table>
<tr><th>Value</th><th>Description</th></tr>
<tr><td><code>top</code></td>
<td>Put the object at the top of its container, not changing its size.</td></tr>
<tr><td><code>bottom</code></td>
<td>Put the object at the bottom of its container, not changing its size. </td></tr>
<tr><td><code>left</code></td>
<td>Put the object at the left edge of its container, not changing its size. This is the
default.</td></tr>
<tr><td><code>right</code></td>
<td>Put the object at the right edge of its container, not changing its size. </td></tr>
<tr><td><code>center_vertical</code></td>
<td>Place object in the vertical center of its container, not changing its size. </td></tr>
<tr><td><code>fill_vertical</code></td>
<td>Grow the vertical size of the object if needed so it completely fills its container. </td></tr>
<tr><td><code>center_horizontal</code></td>
<td>Place object in the horizontal center of its container, not changing its size. </td></tr>
<tr><td><code>fill_horizontal</code></td>
<td>Grow the horizontal size of the object if needed so it completely fills its container.
</td></tr>
<tr><td><code>center</code></td>
<td>Place the object in the center of its container in both the vertical and horizontal axis, not
changing its size. </td></tr>
<tr><td><code>fill</code></td>
<td>Grow the horizontal and vertical size of the object if needed so it completely fills its
container. </td></tr>
<tr><td><code>clip_vertical</code></td>
<td>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.
</td></tr>
<tr><td><code>clip_horizontal</code></td>
<td>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.
</td></tr>
</table></dd>
      <dt><code>android:scaleHeight</code></dt>
        <dd><em>Percentage</em>. The scale height, expressed as a percentage of the drawable's
bound. The value's format is XX%. For instance: 100%, 12.5%, etc.</dd>
      <dt><code>android:scaleWidth</code></dt>
        <dd><em>Percentage</em>. The scale width, expressed as a percentage of the drawable's
bound. The value's format is XX%. For instance: 100%, 12.5%, etc.</dd>
    </dl>
  </dd>
</dl>

</dd>

<dt>example:</dt>

<dd>
<pre class="stx">
&lt;?xml version="1.0" encoding="utf-8"?>
&lt;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%" /&gt;
</pre>
</dd>

<dt>see also:</dt>
<dd>
<ul>
  <li>{@link android.graphics.drawable.ScaleDrawable}</li>
</ul>
</dd>

</dl>







<h2 id="Shape">Shape Drawable</h2>

<p>This is a generic shape defined in XML.</p>

<dl class="xml">

<dt>file location:</dt>
<dd><code>res/drawable/<em>filename</em>.xml</code><br/>
The filename is used as the resource ID.</dd>

<dt>compiled resource datatype:</dt>
<dd>Resource pointer to a {@link android.graphics.drawable.ShapeDrawable}.</dd>

<dt>resource reference:</dt>

<dd>
In Java: <code>R.drawable.<em>filename</em></code><br/>
In XML: <code>@[<em>package</em>:]drawable/<em>filename</em></code>
</dd>

<dt>syntax:</dt>

<dd>
<pre class="stx">
&lt;?xml version="1.0" encoding="utf-8"?>
&lt;<a href="#shape-element">shape</a>
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape=["rectangle" | "oval" | "line" | "ring"] >
    &lt;<a href="#corners-element">corners</a>
        android:radius="<em>integer</em>"
        android:topLeftRadius="<em>integer</em>"
        android:topRightRadius="<em>integer</em>"
        android:bottomLeftRadius="<em>integer</em>"
        android:bottomRightRadius="<em>integer</em>" /&gt;
    &lt;<a href="#gradient-element">gradient</a>
        android:angle="<em>integer</em>"
        android:centerX="<em>integer</em>"
        android:centerY="<em>integer</em>"
        android:centerColor="<em>integer</em>"
        android:endColor="<em>color</em>"
        android:gradientRadius="<em>integer</em>"
        android:startColor="<em>color</em>"
        android:type=["linear" | "radial" | "sweep"]
        android:usesLevel=["true" | "false"] /&gt;
    &lt;<a href="#padding-element">padding</a>
        android:left="<em>integer</em>"
        android:top="<em>integer</em>"
        android:right="<em>integer</em>"
        android:bottom="<em>integer</em>" /&gt;
    &lt;<a href="#size-element">size</a>
        android:width="<em>integer</em>"
        android:color="<em>color</em>"
        android:dashWidth="<em>integer</em>"
        android:dashGap="<em>integer</em>" /&gt;
    &lt;<a href="#solid-element">solid</a>
        android:color="<em>color</em>" /&gt;
    &lt;<a href="#stroke-element">stroke</a>
        android:width="<em>integer</em>"
        android:color="<em>color</em>"
        android:dashWidth="<em>integer</em>"
        android:dashGap="<em>integer</em>" /&gt;
&lt;/shape>
</pre>
</dd>

<dt>elements:</dt>

<dd>
<dl class="tag-list">

  <dt id="shape-element"><code>&lt;shape&gt;</code></dt>
    <dd>The shape drawable. This must be the root element.
      <p class="caps">attributes:</p>
      <dl class="atn-list">
        <dt><code>xmlns:android</code></dt>
          <dd><em>String</em>. <strong>Required.</strong> Defines the XML namespace, which must be
          <code>"http://schemas.android.com/apk/res/android"</code>.
        <dt><code>android:shape</code></dt>
        <dd><em>Keyword</em>. Defines the type of shape. Valid values are:
          <table>
            <tr><th>Value</th><th>Desciption</th></tr>
            <tr><td>{@code "rectangle"}</td>
                <td>A rectangle that fills the containing View. This is the default shape.</td></tr>
            <tr><td>{@code "oval"}</td>
                <td>An oval shape that fits the dimensions of the containing View.</td></tr>
            <tr><td>{@code "line"}</td>
                <td>A horizontal line that spans the width of the containing View. This
                shape requires the {@code &lt;stroke>} element to define the width of the
                line.</td></tr>
            <tr><td>{@code "ring"}</td>
                <td>A ring shape.</td></tr>
          </table>
        </dd>
      </dl>
      <p>The following attributes are used only when {@code android:shape="ring"}:</p>
      <dl class="atn-list">
        <dt><code>android:innerRadius</code></dt>
        <dd><em>Dimension</em>. The radius for the
inner part of the ring (the hole in the middle), as a dimension value or <a
href="more-resources.html#Dimension">dimension resource</a>.</dd>
        <dt><code>android:innerRadiusRatio</code></dt>
        <dd><em>Float</em>. The radius for the inner
part of the ring, expressed as a ratio of the ring's width. For instance, if {@code
android:innerRadiusRatio="5"}, then the inner radius equals the ring's width divided by 5. This
value is overridden by {@code android:innerRadius}. Default value is 9.</dd>
        <dt><code>android:thickness</code></dt>
        <dd><em>Dimension</em>. The thickness of the
ring, as a dimension value or <a
href="more-resources.html#Dimension">dimension resource</a>.</dd>
        <dt><code>android:thicknessRatio</code></dt>
        <dd><em>Float</em>. The thickness of the ring,
expressed as a ratio of the ring's width. For instance, if {@code android:thicknessRatio="2"}, then
the thickness equals the ring's width divided by 2. This value is overridden by {@code
android:innerRadius}. Default value is 3.</dd>
        <dt><code>android:useLevel</code></dt>
        <dd><em>Boolean</em>. "true" if this is used as
a {@link android.graphics.drawable.LevelListDrawable}. This should normally be "false"
          or your shape may not appear.</dd>
      </dl>
  <dt id="corners-element"><code>&lt;corners&gt;</code></dt>
    <dd>Creates rounded corners for the shape. Applies only when the shape is a rectangle.
      <p class="caps">attributes:</p>
      <dl class="atn-list">
        <dt><code>android:radius</code></dt>
        <dd><em>Dimension</em>. The radius for all corners, as a dimension value or <a
href="more-resources.html#Dimension">dimension resource</a>. This is overridden for each
corner by the following attributes.</dd>
        <dt><code>android:topLeftRadius</code></dt>
        <dd><em>Dimension</em>. The radius for the top-left corner, as a dimension value or <a
href="more-resources.html#Dimension">dimension resource</a>.</dd>
        <dt><code>android:topRightRadius</code></dt>
        <dd><em>Dimension</em>. The radius for the top-right corner, as a dimension value or <a
href="more-resources.html#Dimension">dimension resource</a>.</dd>
        <dt><code>android:bottomLeftRadius</code></dt>
        <dd><em>Dimension</em>. The radius for the bottom-left corner, as a dimension value or <a
href="more-resources.html#Dimension">dimension resource</a>.</dd>
        <dt><code>android:bottomRightRadius</code></dt>
        <dd><em>Dimension</em>. The radius for the bottom-right corner, as a dimension value or <a
href="more-resources.html#Dimension">dimension resource</a>.</dd>
      </dl>
      <p class="note"><strong>Note:</strong> Every corner must (initially) be provided a corner
radius greater than 1, or else no corners are rounded. If you want specific corners
to <em>not</em> be rounded, a work-around is to use {@code android:radius} to set a default corner
radius greater than 1, but then override each and every corner with the values you really
want, providing zero ("0dp") where you don't want rounded corners.</p>
    </dd>
  <dt id="gradient-element"><code>&lt;gradient&gt;</code></dt>
    <dd>Specifies a gradient color for the shape.
      <p class="caps">attributes:</p>
      <dl class="atn-list">
        <dt><code>android:angle</code></dt>
        <dd><em>Integer</em>. The angle for the gradient, in degrees. 0 is left to right, 90 is
bottom to top. It must be a multiple of 45. Default is 0.</dd>
        <dt><code>android:centerX</code></dt>
        <dd><em>Float</em>. The relative X-position for the center of the gradient (0 - 1.0).
Does not apply when {@code android:type="linear"}.</dd>
        <dt><code>android:centerY</code></dt>
        <dd><em>Float</em>. The relative Y-position for the center of the gradient (0 - 1.0).
Does not apply when {@code android:type="linear"}.</dd>
        <dt><code>android:centerColor</code></dt>
        <dd><em>Color</em>. Optional color that comes between the start and end colors, as a
hexadecimal value or <a href="more-resources.html#Color">color resource</a>.</dd>
        <dt><code>android:endColor</code></dt>
        <dd><em>Color</em>. The ending color, as a hexadecimal
value or <a href="more-resources.html#Color">color resource</a>.</dd>
        <dt><code>android:gradientRadius</code></dt>
        <dd><em>Float</em>. The radius for the gradient. Only applied when {@code
android:type="radial"}.</dd>
        <dt><code>android:startColor</code></dt>
        <dd><em>Color</em>. The starting color, as a hexadecimal
value or <a href="more-resources.html#Color">color resource</a>.</dd>
        <dt><code>android:type</code></dt>
        <dd><em>Keyword</em>. The type of gradient pattern to apply. Valid values are:
          <table>
            <tr><th>Value</th><th>Description</th></tr>
            <tr><td>{@code "linear"}</td>
                <td>A linear gradient. This is the default.</td></tr>
            <tr><td>{@code "radial"}</td>
                <td>A radial gradient. The start color is the center color.</td></tr>
            <tr><td>{@code "sweep"}</td>
                <td>A sweeping line gradient. </td></tr>
          </table>
        </dd>
        <dt><code>android:useLevel</code></dt>
        <dd><em>Boolean</em>. "true" if this is used as a {@link
android.graphics.drawable.LevelListDrawable}.</dd>
      </dl>
    </dd>
  <dt id="padding-element"><code>&lt;padding&gt;</code></dt>
    <dd>Padding to apply to the containing View element (this pads the position of the View
content, not the shape).
      <p class="caps">attributes:</p>
      <dl class="atn-list">
        <dt><code>android:left</code></dt>
        <dd><em>Dimension</em>. Left padding, as a dimension value or <a
href="more-resources.html#Dimension">dimension resource</a>.</dd>
        <dt><code>android:top</code></dt>
        <dd><em>Dimension</em>. Top padding, as a dimension value or <a
href="more-resources.html#Dimension">dimension resource</a>.</dd>
        <dt><code>android:right</code></dt>
        <dd><em>Dimension</em>. Right padding, as a dimension value or <a
href="more-resources.html#Dimension">dimension resource</a>.</dd>
        <dt><code>android:bottom</code></dt>
        <dd><em>Dimension</em>. Bottom padding, as a dimension value or <a
href="more-resources.html#Dimension">dimension resource</a>.</dd>
      </dl>
    </dd>
  <dt id="size-element"><code>&lt;size&gt;</code></dt>
    <dd>The size of the shape.
      <p class="caps">attributes:</p>
      <dl class="atn-list">
        <dt><code>android:height</code></dt>
        <dd><em>Dimension</em>. The height of the shape, as a dimension value or <a
href="more-resources.html#Dimension">dimension resource</a>.</dd>
        <dt><code>android:width</code></dt>
        <dd><em>Dimension</em>. The width of the shape, as a dimension value or <a
href="more-resources.html#Dimension">dimension resource</a>.</dd>
      </dl>
      <p class="note"><strong>Note:</strong> The shape scales to the size of the container
View proportionate to the dimensions defined here, by default. When you use the shape in an {@link
android.widget.ImageView}, you can restrict scaling by setting the <a
href="{@docRoot}reference/android/widget/ImageView.html#attr_android:scaleType">{@code
android:scaleType}</a> to {@code "center"}.</p>
    </dd>
  <dt id="solid-element"><code>&lt;solid&gt;</code></dt>
    <dd>A solid color to fill the shape.
      <p class="caps">attributes:</p>
      <dl class="atn-list">
        <dt><code>android:color</code></dt>
        <dd><em>Color</em>. The color to apply to the shape, as a hexadecimal
value or <a href="more-resources.html#Color">color resource</a>.</dd>
      </dl>
    </dd>
  <dt id="stroke-element"><code>&lt;stroke&gt;</code></dt>
    <dd>A stroke line for the shape.
      <p class="caps">attributes:</p>
      <dl class="atn-list">
        <dt><code>android:width</code></dt>
        <dd><em>Dimension</em>. The thickness of the line, as a dimension value or <a
href="more-resources.html#Dimension">dimension resource</a>.</dd>
        <dt><code>android:color</code></dt>
        <dd><em>Color</em>. The color of the line, as a
hexadecimal value or <a href="more-resources.html#Color">color resource</a>.</dd>
        <dt><code>android:dashGap</code></dt>
        <dd><em>Dimension</em>. The distance between line dashes, as a dimension value or <a
href="more-resources.html#Dimension">dimension resource</a>. Only valid if {@code
android:dashWidth} is set.</dd>
        <dt><code>android:dashWidth</code></dt>
        <dd><em>Dimension</em>. The size of each dash line, as a dimension value or <a
href="more-resources.html#Dimension">dimension resource</a>. Only valid if {@code
android:dashGap} is set.</dd>
      </dl>
    </dd>

</dl>
</dd> <!-- end  elements and attributes -->

<dt>example:</dt>

<dd>XML file saved at <code>res/drawable/gradient_box.xml</code>:
<pre>
&lt;?xml version="1.0" encoding="utf-8"?>
&lt;shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    &lt;gradient
        android:startColor="#FFFF0000"
        android:endColor="#80FF00FF"
        android:angle="45"/>
    &lt;padding android:left="7dp"
        android:top="7dp"
        android:right="7dp"
        android:bottom="7dp" />
    &lt;corners android:radius="8dp" />
&lt;/shape>
</pre>

    <p>This layout XML applies the shape drawable to a View:</p>
<pre>
&lt;TextView
    android:background="@drawable/gradient_box"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content" />
</pre>

    <p>This application code gets the shape drawable and applies it to a View:</p>
<pre>
Resources res = {@link android.content.Context#getResources()};
Drawable shape = res. {@link android.content.res.Resources#getDrawable(int) getDrawable}(R.drawable.gradient_box);

TextView tv = (TextView)findViewByID(R.id.textview);
tv.setBackground(shape);
</pre>
</dd> <!-- end example -->

<dt>see also:</dt>

<dd>
<ul>
  <li>{@link android.graphics.drawable.ShapeDrawable}</li>
</ul>
</dd>

</dl>