0

I have a simple vector image:

enter image description here

Source:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="21dp"
    android:height="21dp"
    android:viewportWidth="5.5563"
    android:viewportHeight="5.5563">
  <path
      android:pathData="m0.2646,0.2646h5.0271"
      android:strokeWidth="0.264583"
      android:fillColor="#000000"/>
  <path
      android:pathData="M5.2917,0.5292L0.2646,0.5292"
      android:strokeWidth="0.264583"
      android:fillColor="#000000"/>
  <path
      android:pathData="m0.2646,0.2646 l5.0271,5.0271"
      android:strokeWidth="0.264583"
      android:fillColor="#000000"/>
  <path
      android:pathData="M1.8521,3.4396 L4.7625,0.7937"
      android:strokeWidth="0.264583"
      android:fillColor="#800000"/>
  <path
      android:pathData="M0,0h5.5563v5.5563h-5.5563z"
      android:strokeWidth="0.264583"
      android:fillColor="#800000"/>
  <path
      android:pathData="M2.7781,2.7781m-2.7781,0a2.7781,2.7781 0,1 1,5.5563 0a2.7781,2.7781 0,1 1,-5.5563 0"
      android:strokeWidth="0.264583"
      android:fillColor="#ffff00"/>
</vector>

It's size is 21x21 [px], but as it's a vector it can be freely scaled up.

I wish to use this as a background inside a circle WearOS watch app, so I created a new "Empty Composer Activity", and changed the UI code:

@Composable
fun WearApp(res: Int) {
    AppTheme {
        Image(
            painter = painterResource(id = res),
            contentDescription = stringResource(id = R.string.app_name),

            modifier = Modifier.fillMaxSize(),
            contentScale = ContentScale.Fit,
        )
    }
}

Whatever I try, I can't reach my goal. I need this whole image to be inside the watch.

Currently:

enter image description here

Goal:

enter image description here

How am I supposed to do this with the recommended and modern way (with Composer)?

Also, I found this image loading example from the official documentation (link):

Image(
    painter = painterResource(id = R.drawable.dog),
    contentDescription = stringResource(id = R.string.dog_content_description)
)

But when I was importing the "Image", Android Studio marked it as obsolete:

enter image description here

So what is the most up-to-date source for starting with WearOS development?

Daniel
  • 2,318
  • 2
  • 22
  • 53
  • This [modifier](https://github.com/google/horologist/blob/1eacf11151de4fdf36715c6638c606707033ef1a/compose-layout/src/main/java/com/google/android/horologist/compose/layout/FillMaxRectangle.kt#L40) might help. Regarding the obsolete `Image`, there are [four composables available](https://github.com/androidx/androidx/blob/cbde5a083dad07e0b96e16bf70bd729763e1a045/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/Image.kt), only one is deprecated, so just use the other overloaded versions of it. – Gustavo Pagani Mar 20 '23 at 08:45
  • How could I use this modifier you've linked? Shall I import something into gradle? – Daniel Mar 20 '23 at 08:52
  • Yes, more info about importing the library [here](https://github.com/google/horologist/tree/1eacf11151de4fdf36715c6638c606707033ef1a/compose-layout#download). For samples of usage, take a look at the [preview](https://github.com/google/horologist/blob/1eacf11151de4fdf36715c6638c606707033ef1a/compose-layout/src/debug/java/com/google/android/horologist/compose/layout/FillMaxRectanglePreview.kt) and/or [sample](https://github.com/google/horologist/blob/1eacf11151de4fdf36715c6638c606707033ef1a/sample/src/main/java/com/google/android/horologist/sample/FillMaxRectangleScreen.kt) app. – Gustavo Pagani Mar 20 '23 at 11:01
  • Thanks. After adding this library, I got 1000+ errors. Nightmare what android is getting todays. Here is a pastebin if matters: https://pastebin.com/265zHKnx (note: if I remove this library, project builds OK) (Note2: project is an empty composer project Android Studio offered) – Daniel Mar 20 '23 at 12:54
  • [This](https://stackoverflow.com/a/75298544/1401164) should address it – Gustavo Pagani Mar 20 '23 at 13:03

0 Answers0