Mitch
Mitch

Reputation: 1734

Android Vector Drawable Intrinsic

The VectorDrawable refers to the following:

android:width

Used to define the intrinsic width of the drawable. This support all the dimension units, normally specified with dp.

What is meant by "intrinsic"? I thought the point of VectorDrawable was independent of size. If I don't supply the width, my app crashes. What does this value do? I'm not using it, but I have to put in a value anyway.

Upvotes: 1

Views: 733

Answers (1)

Lewis McGeary
Lewis McGeary

Reputation: 7922

The intrinsic dimensions of a VectorDrawable specified by android:width and android:height give the drawable a default size.

Consider the following:

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/example_drawable"/>

What size is this?

Well the ImageView uses wrap_content so it wraps to the size of the drawable. If VectorDrawables didn't have default heights and widths specified then this ImageView wouldn't make sense, it's supposed to wrap to the size of it's content, but the content doesn't have a size!

Hence VectorDrawables must have a default width and height. You can scale them to the size you need them to be, but if there's a situation where they're not being told from somewhere else what size they should be, they need to know what to do.

Upvotes: 3

Related Questions