Q:

Can't figure out layout dependencies in Android

I need to create a layout which should look like this:
 

The TextView content should be wrapped so the ImageView is always at the ent of the text. 
TextView should not overlap with other views regardless of content.
ImageView can have visibility GONE during runtime, so TextView should use the space of ImageView.

My current layout:
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="48dp"
    android:background="@android:color/white">

    <TextView
        android:id="@+id/pref_list_item_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_centerVertical="true"
        android:layout_marginStart="16dp"
        android:fontFamily="sans-serif"
        android:text="Long long"
        android:textSize="@dimen/preference_text_size" />

    <ImageView
        android:id="@+id/pref_list_item_help_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toEndOf="@id/pref_list_item_title"
        android:layout_centerVertical="true"
        android:layout_margin="8dp"
        android:src="@drawable/ic_help_primary_color"
        android:contentDescription="@string/help" />

    <Switch
        android:id="@+id/pref_list_item_switch"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_centerVertical="true"
        android:layout_marginEnd="16dp" />

</RelativeLayout>

ConstraintLayout is an option, but I couldn't create constraints that satisfy my needs.

A:

Using ConstraintLayout you can do it like this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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">

    <TextView
        android:id="@+id/pref_list_item_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:fontFamily="sans-serif"
        android:text="Long long asdasd asd asd aasdadasd"
        android:textSize="@dimen/preference_text_size"
        app:layout_constrainedWidth="true"
        app:layout_constraintHorizontal_chainStyle="packed"
        app:layout_constraintHorizontal_bias="0"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@id/pref_list_item_help_button"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

    <ImageView
        android:id="@+id/pref_list_item_help_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toEndOf="@id/pref_list_item_title"
        android:layout_margin="8dp"
        android:src="@drawable/ic_help_primary_color"
        android:contentDescription="@string/help"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@id/pref_list_item_switch"
        app:layout_constraintStart_toEndOf="@id/pref_list_item_title"
        app:layout_constraintTop_toTopOf="parent"/>

    <Switch
        android:id="@+id/pref_list_item_switch"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

</android.support.constraint.ConstraintLayout>

The TextView and the ImageView are chained together with packed style and horizontal bias of 0 to keep them aligned to the left. The app:layout_constrainedWidth="true" has to be set for the TextView to prevent it from overlapping other Views in case the text gets too long. All this also works well when you want to toggle ImageView's visibility.

