当 TextView 位于 ConstraintLayout 中时,如何对齐文本?我不能使用 layout_width="match_parent
。试过这个,不起作用 :(
android:gravity="start"
android:textAlignment="gravity"
最佳答案
使 TextView 与父级匹配:
android:layout_width="0dp"
然后定义textAlignment属性:
android:textAlignment="viewEnd"
例如,在从左到右的语言中右对齐:
<TextView
android:id="@+id/tv_item"
style="@style/text_highlight_small_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/my_text"
android:textAlignment="viewStart"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Sample Text" />
请注意,您可以为 documentation 中定义的 textAlignment 使用不同的值.
关于android - ConstraintLayout 在 TextView 中右对齐文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50583351/