1

My Vector drawable appear very small on the emulator, I can put 1000.dp width and height it is also small.

With 1000dp width and height

With my custom size: see below

Don't pay attention to the sky and the moon I'm working on. The first image show with 1000.dp width and height and the 2nd show with my custom size (maxWidth / 1.5F for width and maxHeight / 3 for height)

Here is my code:

Image(
                painter = painterResource(id = R.drawable.ic_book_sun),
                contentDescription = "Book",
                contentScale = ContentScale.Fit,
                modifier = Modifier
                    .size(
                        maxWidth / 1.5F,
                       maxHeight / 3
                    )
                    .constrainAs(bookIcon) {
                        centerTo(parent)
                    },


                )

maxWidth and maxHeight are coming from BoxWithConstraints composable so I get the width and height of the screen and display the icon in function of screen size.

Vector drawable code:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:aapt="http://schemas.android.com/aapt"
    android:width="141dp"
    android:height="200dp"
    android:viewportWidth="841"
    android:viewportHeight="1189">
  // Some paths...
>/vector>
Loïc Jackotin
  • 563
  • 3
  • 12
  • 1
    The "canvas" - `viewportWidth` and `viewportHeight` in your vector drawable is roughtly 6 times bigger than the `width` and `height` of the drawable that sits inside the canvas. Typically they woukd be 1:1 ratio - This is not a compose issue. I suggest you recreate the vector drawable correctly. see : https://stackoverflow.com/a/41357976/4252352 – Mark Nov 20 '21 at 21:43
  • When I put the viewportWidth and viewportHeight the same as the width and height the image didn't show. – Loïc Jackotin Nov 20 '21 at 21:45
  • As i said "I suggest you recreate the vector drawable correctly." - you cant simply change these values an expect it to work, path data will not work when you simply change these values - it was created incorrectly in the first place. – Mark Nov 20 '21 at 21:46
  • 1
    Oh I see now! I made this with Inkscape and I forgot to fit the workspace to the vector. Thank you @MarkKeen ! – Loïc Jackotin Nov 20 '21 at 21:47

0 Answers0