I'm trying to find a way to keep text views in a complex layout uniform aligned. Is there a way to position the "1B" TextView
directly under the "1A" TextView
and above the "1C" TextView
whilst avoiding too much nesting?
NB: The "1B" & "1C" TextViews
are in a RelativeLayout
together as part of an expandable RecyclerView
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/linearLayoutA">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/relativeLayoutA">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ibA"
android:src="@mipmap/ic_launcher_round"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tvA"
android:layout_toEndOf="@+id/ibA"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/relativeLayoutB">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tvB"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ivC"
android:src="@mipmap/ic_launcher_round"
android:layout_below="@id/tvB"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tvC"
android:layout_below="@id/tvB"
android:layout_toEndOf="@id/ivC"/>
</RelativeLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
Use ConstraintLayout: