Useful Modifiers In Jetpack Compose Part — II
2 min readOct 27, 2023
If you haven’t read the first article on it , READ IT FROM HERE .
1). offset Modifier
Through offset
modifier , we can change the x and y position of any composable functions.
@Composable
fun OffsetModifier(
modifier: Modifier = Modifier
) {
Box(
modifier = modifier
.padding(50.dp)
.background(Color.LightGray)
.fillMaxWidth()
.height(100.dp),
contentAlignment = Alignment.TopCenter
) {
Text(
text = stringResource(R.string.offset_content),
modifier = Modifier.offset(x = 0.dp, y = -(15.dp)),
style = TextStyle(
color = Color.Black,
fontSize = 20.sp
)
)
}
}
As you can see above in the offset
modifier , we passed x to 0.dp and y to -15.dp
. So that it change the position to upside. if we pass 15.dp
then it will move to downside.
Same for x — if + , it will move to the right side , otherwise left side.