Home > OS >  How can I make the width of MaterialTextView wrap_content but no larger than MaterialButton in Const
How can I make the width of MaterialTextView wrap_content but no larger than MaterialButton in Const

Time:04-17

<?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="wrap_content"
    tools:ignore="HardcodedText">

    <com.google.android.material.textview.MaterialTextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:text="abcdefghijklmn"
        android:textSize="17.5sp"
        app:layout_constraintEnd_toStartOf="@id/btn"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <com.google.android.material.button.MaterialButton
        android:id="@ id/btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:text="do something"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

enter image description here

How can I make the width of MaterialTextView wrap_content but no larger than MaterialButton in ConstraintLayout?

I did that in XML above, But the MaterialTextView Not wrap_content it seems like match_parent.

I watched this small_text

Long Text:

long_text

  • Related