Home > other >  Edit Text doesn't wrap around content in Android Studio
Edit Text doesn't wrap around content in Android Studio

Time:02-13

I've this simple bit of xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp"
    tools:context=".MainActivity">

    <EditText
        android:id="@ id/cost_of_service"
        android:layout_width="160dp"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal"

        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>
    
</androidx.constraintlayout.widget.ConstraintLayout>

It seems that the EditText does not wrap itself horizontally even though the layout_height is set to "wrap content". Could anybody tell me why this is occurring? Sorry if this might seem like a dumb question, I'm quite new to android.

CodePudding user response:

I think that you want the edit text to adjust its size according to the text given by the user, in the code you have set the width to be fixed and you have used plain text not multiline so if the users input the text and the length of the text crosses 16d0dp so the text will start moving behind and you don't want this that is why you set the height to wrap content, just use multiline text instead. Your problem will be solved.

CodePudding user response:

Try changing the default background and text size:

android:background="@null"
android:textSize="1sp"

    
  • Related