I need to indent the same size in the second text view on the right as in the first one on the left. I tried to do through
android: text alignment = "textend"
android: layout_margin End = "20dp",
now I have it done like this:
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/light_gray">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="TestTest"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAlignment="textEnd"
android:layout_marginEnd="20dp"
android:text="TestTest"/>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
but I think it should be done differently
enter image description here
2
Answers
You can simply use
layout_gravity
and set it toend
to push the 2nd textView towards the end.Also note I have set the width to
wrap_content
as opposed tomatch_parent
.Have also used a margin of 20 dp to offset the 2nd TextView from the edge of parent.
TextAlignment attribute specifies the position of text inside the TextView and won’t work if the view is set to
wrap_content
Using
android:weightSum
You Can Separate.Then For Second TextView Only Use
android:textAlignment="viewEnd"
Then Text Gravity Goes To Width End