布局中实现:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"//放在页面顶部
android:gravity="center"
android:orientation="horizontal" >
<EditText
android:id="@+id/product_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/bg_edittext_xml"//自定义EditText样式
android:hint="商品类别名称"
android:padding="10dp" />
<ImageButton
android:id="@+id/bt_product_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/product_search"
android:layout_centerVertical="true"
android:layout_marginRight="12dp"
android:layout_marginTop="42dp"
android:background="@drawable/search_more" />
</RelativeLayout>
也可以直接拖拉ImageButton进布局,修改ImageButton的layout_marginTop到合适的效果