티스토리 뷰

공부/Android

[Compose] 두 Text 기준선 맞추기

데자와 맛있다 2023. 9. 16. 19:19

두개의 글자 크기가 다른 Text를 row로 나란히 놔두려는데

 

            Row (verticalAlignment = Alignment.CenterVertically){
                Text(
                    text = calorie.toString(),
                    style = HabitTheme.typography.extraLargeBoldTextPurpleNormal
                )
                Spacer(modifier = Modifier.size(4.dp))
                Text(
                    text = stringResource(id = R.string.home_bottom_sheet_kcal),
                    style = HabitTheme.typography.headTextPurpleNormal
                )
            }

이렇게 하니깐

묘하게 틀어진 모습....

 

Row (verticalAlignment = Alignment.CenterVertically){
                Text(
                    modifier = Modifier.alignByBaseline(),
                    text = calorie.toString(),
                    style = HabitTheme.typography.extraLargeBoldTextPurpleNormal
                )
                Spacer(modifier = Modifier.size(4.dp))
                Text(
                    modifier = Modifier.alignByBaseline(),
                    text = stringResource(id = R.string.home_bottom_sheet_kcal),
                    style = HabitTheme.typography.headTextPurpleNormal
                )
            }

글자 아래를 기준으로 두 Text 가 정렬된 모습

Text의 Modifier.alignByBaseline을 사용하면된다

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함