Reputation: 30107
I have two buttons defined in XML
<Button
android:layout_alignParentBottom="true"
android:id="@+id/takepic_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Take_Pic"
android:layout_gravity="left"
android:layout_alignParentLeft="true"
/>
<Button
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:id="@+id/cancel_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Cancel"
android:layout_gravity="right"
/>
My question is how can I tell android that set the width of second button equal to whatever is the width of first button.
Update: I am looking for XML solution
Upvotes: 1
Views: 2920
Reputation: 9033
btn1=(Button) findViewById(R.id.button1);
btn2=(Button) findViewById(R.id.button2);
int i=btn1.getWidth();
btn2.setWidth(i);
Upvotes: 2
Reputation: 13
In xml for two buttons sideby side in a horizontal layout use
android:layout_weight="1"
hope this helps
Upvotes: 0
Reputation: 14938
Use the android:layout_weight properties set to the same value for both of your button.
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
Upvotes: 1