Android developer文档中有对resource的drawable进行详细介绍
现在我们就一一介绍:
Bitmap File
A bitmap file is a .png
, .jpg
, or .gif
file. Android creates a Drawable
resource for any of these files when you save them in the res/drawable/
directory.
-
文件路径
-
res/drawable/filename.png
(.png
,.jpg
, or.gif
)
The filename is used as the resource ID.
compiled resource datatype:
-
Resource pointer to a
BitmapDrawable
.
引用方式:
-
In Java:
R.drawable.filename
In XML:@[package:]drawable/filename
example:
-
With an image saved at
res/drawable/myimage.png
, this layout XML applies the image to a View:<ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/myimage" />
The following application code retrieves the image as a
Drawable
:Resources res =
getResources()
; Drawable drawable = res.getDrawable
(R.drawable.myimage);