Thread
#compose
    zalewski.se

    zalewski.se

    2 years ago
    Is it possible to attach the
    TextField
    to the right side of the screen? I’m trying to use
    ConstraintLayout
    for this, where everything looks as expected with
    Text
    element, but when I changed it to
    TextField
    it looks like the:
    right constrainTo parent.right
    doesn’t work 🤔 To give you some code: This is sample with Text:
    ConstraintLayout(
                modifier = Modifier.fillMaxWidth().wrapContentHeight(),
                constraintSet = ConstraintSet {
                    tag("amountTag").apply {
                        right constrainTo parent.right
                        right.margin = 16.dp
                        horizontalBias = 1.0f
                        centerVertically()
                    }
                }
        ) {
            Text(
                    modifier = Modifier.tag("amountTag"),
                    fontSize = 16.sp,
                    text = rate.value.toString()
            )
        }
    And when I just changed
    Text
    to TextField:
    TextField(
                    modifier = Modifier.tag("amountTag"),
                    value = value,
                    onValueChange = {
                        value = it
                    }
            )
    Also I tried to add some modifiers to
    TextField
    like:
    .wrapContentWidth(Alignment.End)
    but same result.
    a

    Anastasia [G]

    2 years ago
    I think this is because in that case TextField is not wrapping the input text and is actually taking more space horizontally. And within this width the text is aligned to the left. To check this, you could add a
    background()
    modifier to the TextField to see how much space it occupies. If this is indeed the case, then you could either try to make TextField wrap the content by setting the minimum width to something other than 0 (e.g.
    preferredWidthIn(minWidth = 5.dp)
    ). Or you could align the input text within the TextField to the right (using the
    textAlign
    param of the TextStyle param of the TextField).
    zalewski.se

    zalewski.se

    2 years ago
    I see, thanks! 🙇‍♂️