小编Raf*_*iul的帖子

如何在 Jetpack compose 中制作 FlipCard 动画

我有一个现有的应用程序,我在 XML 中使用 Objectanimator 实现了如下所示的 FlipCard 动画。如果我点击一张卡片,它会水平翻转。但现在我想将它迁移到 jetpack compose。那么是否可以在 jetpack compose 中制作翻盖动画?

https://i.stack.imgur.com/pU4rt.gif

更新

最后,我已经结束了这个。虽然我不知道这是否正确,但我得到了我想要的。如果有更好的替代方案,您可以提出建议。谢谢你。

方法一:使用animate*AsState

    @Composable
    fun FlipCard() {
        
        var rotated by remember { mutableStateOf(false) }

        val rotation by animateFloatAsState(
            targetValue = if (rotated) 180f else 0f,
            animationSpec = tween(500)
        )

        val animateFront by animateFloatAsState(
            targetValue = if (!rotated) 1f else 0f,
            animationSpec = tween(500)
        )

        val animateBack by animateFloatAsState(
            targetValue = if (rotated) 1f else 0f,
            animationSpec = tween(500)
        )

        val animateColor by animateColorAsState(
            targetValue = if (rotated) Color.Red …
Run Code Online (Sandbox Code Playgroud)

android android-animation android-jetpack-compose

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

Jetpack Compose BottomNavBar 标签重叠 图标

我试图实现 jetpack compose 底部导航栏。但我遇到了这个问题。每当标签没有足够的空间时,它就会与图标重叠。我错过了什么吗?有没有自动截断或缩小文本之类的解决方案?

compose_version = '1.0.0-beta09'

[1]:https://i.stack.imgur.com/gmD34.png

我的代码

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            val navController = rememberNavController()
            val items = listOf(
                Screen.Profile,
                Screen.FriendsList,
                Screen.Notification,
                Screen.Setting
            )

            Scaffold(
                bottomBar = {
                    BottomNavigation(
                        backgroundColor = MaterialTheme.colors.surface,
                        elevation = 8.dp
                    ) {
                        val navBackStackEntry by navController.currentBackStackEntryAsState()
                        val currentRoute = navBackStackEntry?.destination?.route
                        items.forEachIndexed { index, screen ->
                            BottomNavigationItem(
                                icon = {
                                    when (index) {
                                        0 -> Icon(Icons.Filled.Person, "Profile")
                                        1 -> Icon(
                                            painterResource(id = R.drawable.ic_friends),
                                            "Friends"
                                        )
                                        2 -> Icon(Icons.Filled.Notifications, "Notification")
                                        else -> …
Run Code Online (Sandbox Code Playgroud)

android android-bottomnav android-jetpack-compose jetpack-compose-navigation

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