Reputation: 1371
I have a double constraint layout, one is the box which takes all the screen and the second one contains some views (an editTextview in particular). I want that my editText takes all the remaining space on the right, as in the photo below
I've put layout_width = 0dp to achieve this purpose, but it's not working. In fact, the editText seems to be much shorter; I still can write numbers, but they all remain in that portion of space (it shows the last 6 numbers in that part of the editText).
Moreover, when I stop typing and the keyboard disappears, all the numbers, which I've written before, expand on the right, as you can see here:
I've tried to solve the problem using layout_width = 500dp or similar, but the final result is not what I'd like to achieve. I want to be able to write numbers for ALL the line and when I reach it, the first numbers have to disappear from the view and the new written numbers have to appear on the right (I mean, it must show the last 30 characters for example).
Here is the part of the layout with the problem:
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/boxEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:background="@drawable/layout_border"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tabLayout">
<TextView
android:id="@+id/buttonPrefix"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:text="+39"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@+id/boxEditText"
app:layout_constraintTop_toTopOf="parent"></TextView>
<View
android:id="@+id/verticalLine"
android:layout_width="1dp"
android:layout_height="25dp"
android:layout_margin="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="@android:color/black"
app:layout_constraintBottom_toBottomOf="@+id/buttonPrefix"
app:layout_constraintStart_toEndOf="@+id/buttonPrefix"
app:layout_constraintTop_toTopOf="@+id/buttonPrefix" />
<EditText
android:id="@+id/editTextPhone"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="@drawable/edit_text_border"
android:hint="@string/Telefono"
android:inputType="phone"
android:maxLines="1"
app:layout_constraintBottom_toBottomOf="@+id/verticalLine"
app:layout_constraintStart_toEndOf="@+id/verticalLine"
app:layout_constraintTop_toTopOf="@+id/verticalLine" />
</androidx.constraintlayout.widget.ConstraintLayout>
Upvotes: 0
Views: 727
Reputation: 1619
I'm not sure which pictures show the working and which ones show the not working examples, but i noticed this:
You forgot the end constraint:
app:layout_constraintEnd_toEndOf="parent"
And if the text overlaps your background you can probably add some padding:
android:paddingEnd="16dp"
Upvotes: 1
Reputation: 1381
If i have understood good, you can write
android:gravity="right"
In that way, you will start typing from the right side, and as you keep typing, the first numbers will go to the left. Now, if you want a specific number of characters to show up, you can achieve that by changing the size of the number.
Upvotes: 0