小编Moh*_*qer的帖子

JetPack Compose 伴奏者寻呼机 lerp 未找到

我正在学习伴奏寻呼机,我想在寻呼机上设置效果。

我想像文档一样使用lerp方法

Modifier.graphicsLayer {
    // Calculate the absolute offset for the current page from the
    // scroll position. We use the absolute value which allows us 
    // to mirror any effects for both directions
    val pageOffset = 
        calculateCurrentOffsetForPage(page).absoluteValue

    // We animate the scaleX + scaleY, between 85% and 100%
    lerp(
      start = 0.85f,
      stop = 1f,
      fraction = 1f - pageOffset.coerceIn(0f, 1f)).also { scale ->
        scaleX = scale
        scaleY = scale
      }

    // We animate the alpha, between 50% and …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-jetpack-compose jetpack-compose-accompanist

18
推荐指数
1
解决办法
5361
查看次数

jetpack 撰写 Lottie addAnimataionListener

我想在 Jetpack Compose 中使用 Lottie。这是我的代码

val logoAnimationComposition by rememberLottieComposition(
    spec = LottieCompositionSpec.RawRes(
        resId = R.raw.twitter_logo_motion
    )
)
val logoAnimationProgress by animateLottieCompositionAsState(
    composition = logoAnimationComposition,
    isPlaying = true
)
LottieAnimation(
    modifier = Modifier.size(
        size = logoSize
    ),
    composition = logoAnimationComposition,
    progress = logoAnimationProgress
)
Run Code Online (Sandbox Code Playgroud)

我需要知道这个动画什么时候结束。

我可以用我从 UI 设计师那里知道的动画持续时间来处理它,但这不是一个好方法。

并且文档没有提及任何相关内容。

我能做些什么?

android kotlin lottie android-jetpack-compose

6
推荐指数
2
解决办法
3178
查看次数

为什么Horizo​​ntalPager的自动滚动在手动滚动后就停止了?

我有一个HorizontalPager

val pageCount = bannerList.size
val startIndex = Int.MAX_VALUE / 2
val pagerState = rememberPagerState(initialPage = 100)
HorizontalPager(
    count = Int.MAX_VALUE,
    state = pagerState,
    contentPadding = PaddingValues(
        horizontal = 20.dp
    ),
    modifier = Modifier
        .fillMaxWidth()
) { index ->
// content goes here
}
Run Code Online (Sandbox Code Playgroud)

我让它像横幅一样每 4 秒滚动一次LaunchedEffect

LaunchedEffect(
    key1 = Unit,
    block = {
        repeat(
            times = Int.MAX_VALUE,
            action = {
                delay(
                    timeMillis = 4000
                )
                pagerState.animateScrollToPage(
                    page = pagerState.currentPage + 1
                )
            }
        )
    })
Run Code Online (Sandbox Code Playgroud)

它每 4 …

kotlin android-jetpack-compose jetpack-compose-accompanist

6
推荐指数
1
解决办法
1614
查看次数

jetpack compose 将可组合性切成两半

如何在 jetpack compose 中剪切如下图所示的可组合Text项Button?

在此输入图像描述

android android-jetpack-compose

5
推荐指数
1
解决办法
1910
查看次数

Jetpack compose RememberSwipeableState 是内部的

我想使用 jetpack compose 创建一个可滑动组件并作为文档Gestures | JetpackCompose我应该使用rememberSwipeableState. 但当我想使用它时,我遇到了这个错误:

Cannot access 'rememberSwipeableState': it is internal in 'androidx.compose.material3'
Run Code Online (Sandbox Code Playgroud)

我应该怎么办?

android android-jetpack-compose

3
推荐指数
1
解决办法
1500
查看次数

Compose Desktop 可组合项名称以小写字母开头

众所周知,ComposableJetpack Compose 中的函数名称应以大写字母开头。但当Compose Desktop我使用大写字母作为我的Composable第一个字母时,编辑器会显示警告!

Function name 'App' should start with a lowercase letter

我只想从Android我的项目中复制并粘贴大量代码。

我该如何解决这个问题?

android-jetpack-compose compose-desktop

3
推荐指数
1
解决办法
654
查看次数

如何在 kotlin 中将 BitmapDrawable 或 Bitmap 转换为 ImageBitmap

我需要更改Bitmap?或BitmapDrawable显示ImageBitmap它,coil 这是我的代码

val bitmap = BlurhashDecoder.decode(blurhash, 4, 3)
Image(
    bitmap = bitmap as ImageBitmap,
    modifier = modifier,
    contentScale = ContentScale.Crop,
    contentDescription = ""
)
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我收到此错误

java.lang.ClassCastException: android.graphics.Bitmap cannot be cast to androidx.compose.ui.graphics.ImageBitmap
Run Code Online (Sandbox Code Playgroud)

kotlin android-jetpack-compose

2
推荐指数
1
解决办法
1959
查看次数

Jetpack Compose 检测拖动手势并检测交互源

我想使用 jetpack compose 开发一个浮动可拖动按钮,我还需要知道用户拖动交互何时开始以及何时结束。

    Box(
        modifier = Modifier.fillMaxSize(),
        contentAlignment = Alignment.Center,
        content = {
            val interactionSource = remember { MutableInteractionSource() }
            val interactions = remember { mutableStateListOf<Interaction>() }
            LaunchedEffect(interactionSource) {
                interactionSource.interactions.collect { interaction ->
                    Log.i("dragInteraction", "-> $interaction")
                }
            }
            var offsetX by remember { mutableStateOf(0f) }
            var offsetY by remember { mutableStateOf(0f) }

            Surface(
                modifier = Modifier
                    .offset {
                        IntOffset(
                            x = offsetX.roundToInt(),
                            y = offsetY.roundToInt()
                        )
                    }
                    .size(60.dp)
                    .pointerInput(Unit) {
                        detectDragGestures { change, dragAmount ->
                            offsetX += dragAmount.x
                            offsetY …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-jetpack-compose compose-desktop

1
推荐指数
1
解决办法
4678
查看次数