I have the following RelativeLayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="2dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp">
<TextView
android:id="@+id/x_memtxtlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/x_memamtlay"
android:textColor="#000000"
android:textSize="22sp"
android:paddingLeft="3dp">
</TextView>
<EditText
android:id="@+id/x_memamtlay"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_width="70dp"
android:inputType="number"
android:singleLine="true"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:background="@drawable/edittext_greybg"
android:visibility="gone">
</EditText>
<TextView
android:id="@+id/x_memamt"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:textColor="#000000"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:textSize="20sp"
android:background="@drawable/number_fill">
</TextView>
</RelativeLayout>
Now I have to set EditText(@+id/x_memamtlay) visibility to gone/visible and 2nd TextView(@+id/x_memamt) visibility to gone/visible regularly in my activity based on some requirements.Either EditText or TextView will be visible at a time.
Problem is, in 1st TextView(@+id/x_memtxtlay),
when I set android:layout_toLeftOf=”@+id/x_memamtlay” : (to left of EditText)

But when I set android:layout_toLeftOf=”@+id/x_memamt” : (to left of 2nd TextView)

How can I adjust the layout so that 1st TextView aligns left to both EditText and 2nd TextView.
Try this just a minor change in your code::