无法在Android Studio上导入drawArc()、drawRect(0等)

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

我是 Jetpack Compose 的初学者。我一直在使用不同的示例和示例代码进行研究。其中一个特别是我一直遇到的问题。真令人沮丧。

这是代码(来自https://developersbreach.com/custom-shape-animations-pulsating-circles-canvas-compose/

@Composable
fun AnimateCircle() {

    // Initial float value for animation start.
    val animateCircle = remember { Animatable(0f) }

    Box(
        modifier = Modifier.fillMaxSize(),
        contentAlignment = Alignment.Center
    ) {
        // Animation properties
        LaunchedEffect(animateCircle) {
            animateCircle.animateTo(
                targetValue = 1f,
                animationSpec = infiniteRepeatable(
                    animation = tween(
                        durationMillis = 1000,
                        easing = LinearEasing
                    ),
                    repeatMode = RepeatMode.Restart
                )
            )
        }

        // Draw arc in canvas which forms animated circle, repeatable.
        Canvas(
            modifier = Modifier
        ) {
            drawArc(
                color = Color(0xFF302522),
                startAngle = 45f,
                sweepAngle = 360f * animateCircle.value,
                useCenter = false,
                size = Size(80f, 80f),
                //style = Stroke(16f, cap = StrokeCap.Round)
            )
        }
    }
}

由于某种原因,它不允许我导入drawArc。我那里有 androidx.compose.ui.graphics.Canvas 。

尝试了drawRect、drawCircle等,都是一样的。我希望下拉列表有导入选项。

这就是我得到的。

import android.os.Bundle
import android.util.Size
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Canvas
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.PaintingStyle.Companion.Stroke
import androidx.compose.ui.tooling.preview.Preview
import com.example.animatecircle3.ui.theme.AnimateCircle3Theme
android canvas import drawing jetpack
1个回答
0
投票
// change this
import androidx.compose.ui.graphics.Canvas
// with this  
import androidx.compose.foundation.Canvas    
© www.soinside.com 2019 - 2024. All rights reserved.