如何使用 Composer 将图像缩放到圆圈内?

问题描述 投票:0回答:0

我有一个简单的矢量图:

来源:

<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>

它的大小是 21x21 [px],但由于它是一个矢量,所以可以自由放大。

我想用它作为一个圆形 WearOS 手表应用程序的背景,所以我创建了一个新的“Empty Composer Activity”,并更改了 UI 代码:

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

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

无论我尝试什么,我都无法达到我的目标。我需要这整个图像inside watch.

目前:

目标:

我应该如何使用推荐的现代方式(使用 Composer)来做到这一点?

此外,我从官方文档(链接)中找到了这个图像加载示例:

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

但是当我导入“图像”时,Android Studio 将其标记为过时:

那么开始 WearOS 开发的最新资源是什么?

android wear-os
© www.soinside.com 2019 - 2024. All rights reserved.