both are video links , text is shaking while swing animation
video link
video link First Check the video , in Video u can see Text is jerking or shaking , i don’t want this type of shaking in text, i want smooth animation without shaking text, i also use text over image and canvas also but not working
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.tween
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.TransformOrigin
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import network.chaintech.testapplication.ui.theme.TestApplicationTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
Swing()
}
}
}
@Composable
fun Swing() {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.TopCenter,
) {
Panel()
Nail(Modifier.align(Alignment.TopCenter))
}
}
@Composable
fun Panel() {
val angleOffset = 10f
val infiniteTransition = rememberInfiniteTransition(label = "")
val angle by infiniteTransition.animateFloat(
initialValue = -angleOffset,
targetValue = angleOffset,
animationSpec = infiniteRepeatable(
animation = tween(
durationMillis = 4000,
easing = FastOutSlowInEasing
),
repeatMode = RepeatMode.Reverse,
), label = ""
)
Surface(
modifier = Modifier
.size(150.dp)
.rotate(angle),
color = Color.Red,
shape = RoundedCornerShape(8.dp),
) {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Text(
text = "Hello, Jetpack",
color = Color.White,
fontSize = 24.sp,
fontStyle = FontStyle.Normal,
modifier = Modifier.padding(5.dp)
)
}
}
}
@Composable
fun Nail(modifier: Modifier) {
Surface(
modifier = modifier
.padding(top = 2.dp)
.size(32.dp),
color = Color.Red,
shape = CircleShape,
border = BorderStroke(width = 8.dp, color = Color.White)
) {}
}
New contributor
Ishant Sharma is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.