I have this simple layout with 2 icons and SearchView between them. I want SearchView to be between those two icons (same as match_constraint in ConstraintLayout). I want to use RelativeLayout, because negative margins doesn't work in ConstraintLayout (you have to use spacers which is not effective in my case).
This solution doesn't work. It will push second icon off the view and SearchView will match_parent in that case. Reason for negative margin: Gap between Icon and SearchView in app is big even without margin. So I want to use negative margin for icons to bring them closer to the edge of SearchView(EditText inside)
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="16dp"
android:layout_marginTop="32dp">
<ImageButton
android:id="@+id/icon_1"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:background="@android:color/transparent"
android:layout_gravity="center_horizontal"
android:src="@drawable/ico_1" />
<android.support.v7.widget.SearchView
android:id="@+id/action_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/icon_1"
android:background="@color/colorTransparent"
android:backgroundTint="@color/colorTransparent"
android:focusedByDefault="false"
app:closeIcon="@null"
app:iconifiedByDefault="false"
app:searchHintIcon="@null"
app:searchIcon="@null">
</android.support.v7.widget.SearchView>
<ImageButton
android:id="@+id/icon_2"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_toEndOf="@id/action_search"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="15dp"
android:adjustViewBounds="true"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:src="@drawable/ico_2" />
</RelativeLayout>
Image:
