如何使材料TextView wrap_content的宽度在Condectlayout中不超过MitaledButton?
<?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>
我如何使材料TextView的宽度
wrap_content
,但不超过youteral button
in condect> CondectlaintLayout
代码>?
我在上面的xml
中做到了这一点,但是材料TextView
不是wrap_content
,似乎match_parent
。
我看了这问题那对我没有帮助,或者我错过了一些东西。
<?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>
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 question and that was not helpful for me or maybe I missed something.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要设置
材料TextView的宽度
以将其包装到其内容中,但不超过材料button
您需要在材料TextView xml xml布局中添加以下属性:android:layout_width = “ wrap_content”
,app:layout_constrainingwidth =“ true”
和app:layout_constrainthorizontal_bias =“ 0”
。示例如下所示:
小文本:
长文本:
To set the width of
MaterialTextView
to wrap to its content but no larger thanMaterialButton
you need to add the below attributes in your MaterialTextView xml layout:android:layout_width="wrap_content"
,app:layout_constrainedWidth="true"
andapp:layout_constraintHorizontal_bias="0"
.Example is like the below:
Small Text:
Long Text: