Help me please achieve following arrangement of two TextViews:
match_parent
). Both TextViews should be wrap_content
and pressed to their side.Wrap Content: Wrap content takes the length of the text and wraps its content. Example: “This is a Wrap Text”. The wrap content starts wrapping from “This” and ends at “text”.
Posted on Apr 28, 2022. Learn how to create a multiline TextView in Android application. The Android TextView widget is used to display text in your application. When you have a text that's longer than one line, then the TextView will automatically put the text in multiple lines.
You can use both LinearLayout
or ConstraintLayout
, and the main here is android:maxWidth
this we need to give one view and the other view will get adjust based on that.
ConstraintLayout
example
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/start"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toStartOf="@+id/end"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="Loooooooooong Texxxxxxxt!!!!!!!!!!!!" />
<TextView
android:id="@+id/end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="250dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:text="May be this is short"/>
</androidx.constraintlayout.widget.ConstraintLayout>
LinearLayout
Example:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Loooooooooong Texxxxxxxt!!!!!!!!!!!!!!!!!!!!!!" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="250dp"
android:text="May be this is short with maxwidth"/>
</LinearLayout>
Have you tried Flexbox layout? Looks like it covers your case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With