Reputation: 2445
I am wanting a button to be aligned to the the bottom and right of a EditText box.
My code is below:
<RelativeLayout
android:id="@+id/global_only_available_home_delivery_postcode_check_layout"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:layout_gravity="right"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/global_only_available_home_delivery_postcode_check_text_phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/delivery_edit_hint"
android:layout_marginLeft="@dimen/pdp_status_delivery_margin_5"
android:layout_marginTop="@dimen/pdp_status_delivery_margin_10"
android:textSize="14sp"
android:inputType="text" />
<Button
android:id="@+id/fragment_pdp_deliverygo"
style="@style/alternatesmallbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="35dp"
android:minHeight="35dp"
android:layout_marginLeft="10dp"
android:text="@string/pdp_delivery_go"
android:layout_gravity="right"
android:layout_margin="5dp"
android:layout_toRightOf="@+id/global_only_available_home_delivery_postcode_check_text_phone"
android:layout_alignBottom="@+id/global_only_available_home_delivery_postcode_check_text_phone"
android:visibility="visible" />
</RelativeLayout>
and here is what I get button alignment
As you can see from the image, the button doesn't seem to be aligned to the bottom of the textview.
Can anyone help?
Upvotes: 0
Views: 62
Reputation: 7698
This is because you have android:layout_margin="5dp"
for the button. This assigns a margin of 5dp
to the bottom of the button and it appears as if it is not aligned to the bottom. You should remove it and assign margins individually to other sides if you want eg:
android:layout_marginRight="5dp"
android:layout_marginTop="5dp" // etc (optional)
Upvotes: 1
Reputation: 24853
Try this..
Use android:layout_alignParentRight="true"
and android:layout_centerVertical="true"
<Button
android:id="@+id/fragment_pdp_deliverygo"
style="@style/alternatesmallbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="35dp"
android:minHeight="35dp"
android:layout_marginLeft="10dp"
android:text="@string/pdp_delivery_go"
android:layout_gravity="right"
android:layout_margin="5dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/global_only_available_home_delivery_postcode_check_text_phone"
android:layout_alignBottom="@+id/global_only_available_home_delivery_postcode_check_text_phone"
android:visibility="visible" />
Upvotes: 0