I have a Linear layout with vertical orientation in which I'm inserting several view groups. One of them is:
<LinearLayout
android:id="@+id/addedit_updowncontrol"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView2"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<Button
android:id="@+id/addedit_btndecrement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_weight="0.1"
android:text="-" />
<EditText
android:id="@+id/addedit_txtQuantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="90dp"
android:layout_weight="0.4"
android:layout_alignParentTop="true"
android:inputType="numberDecimal" />
<Button
android:id="@+id/addedit_btnIncrement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_weight="0.1"
android:layout_toLeftOf="@+id/addedit_units"
android:text="+" />
<Spinner
android:id="@+id/addedit_units"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true" />
</LinearLayout>
This gives me a view that looks like this (apologies for the link, I wish there was a better way). This is unacceptable as the Button does not align with the EditText.
I tried switching to RelativeLayout, which gives me something like this. This is unacceptable as the two buttons (-) and (+) are not of the same width.
I guess what I'm trying to achieve is: (1) The baseline of the Button is aligned with the other controls in the row. (2) The two button are of the same width.
I seem to be able to achieve (1) with RelativeLayout and (2) with LinearLayout. But not both.
Can anyone help me please?
use
android:gravity="center_vertical"
in your linearlayout. All items will be centered
Change the orientation of Linear Layout to horizontal and set baselinealigned attribute to true in xml. Play with layout_weights. Assign the same weight to both buttons. Hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With