Well, I would suggest instead of doing all this, you can just add labels alignLeft, alignTop, alignBottom, alignTop to the image you use, like this
<ImageView android:id="@+id/img_view_search" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@id/edt_text_search" android:layout_alignRight="@id/edt_text_search" android:layout_alignTop="@id/edt_text_search" android:src="@drawable/search_selected" android:padding="2dp" />
edt_text_search is the edittext identifier
user3975195
source share